Welcome Guest! To enable all features please Register.

Notification

Icon
Error

New Topic Post Reply
Reading the first letter from a string VB.net?
Guest
#1 Posted : Monday, August 30, 2010 8:00:06 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
For my computing work we have been set a task to write in a string to the console, and pick out the first letter. which string manipulation technique is best for this?
Sponsor

Soan
#2 Posted : Monday, August 30, 2010 8:00:37 AM(UTC)
Rank: Administration
Soan

Joined: 1/9/2010(UTC)
Posts: 393
Points: 1,158
Location: India
If your input box is a textbox with name as TextBox1, then you can use the following code line to get the first character of the string entered by user in TextBox1.
TextBox1.Text = TextBox1.Text.Substring(0, 1)

Substring(0,1) --> 0 here means the starting point which is in our case is the first letter. You can change the starting point as per your requirement. But remember that the counting always starts from zero (0).
1 here means how many characters whiic in our case is 1 character. if you want to get more than 1 charcters from start of string, you can change this value as per your requirement.
Guest
#4 Posted : Wednesday, February 01, 2012 11:16:26 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
How do you do that for multiple words like "hello How are you today?"
Where it becomes (H H A Y T)
Guest
#3 Posted : Wednesday, February 01, 2012 11:19:02 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
Soan;361 wrote:
If your input box is a textbox with name as TextBox1, then you can use the following code line to get the first character of the string entered by user in TextBox1.
TextBox1.Text = TextBox1.Text.Substring(0, 1)

Substring(0,1) --> 0 here means the starting point which is in our case is the first letter. You can change the starting point as per your requirement. But remember that the counting always starts from zero (0).
1 here means how many characters whiic in our case is 1 character. if you want to get more than 1 charcters from start of string, you can change this value as per your requirement.


How do you do that for multiple words where "Hello How are you today?" becomes (h h a y t)?
Guest
#5 Posted : Thursday, February 02, 2012 5:21:37 PM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
Use string.split with " " as the split and send each string into a variable array.

Use a loop to go through each variable(x) and take the first letter.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.