Link to home
Start Free TrialLog in
Avatar of clebo99
clebo99

asked on

Probably the Easiest String Question Ever

Ok, I'm using a streamreader to read pretty long lines of text.  What I want to do is say get specific parts of the line and put them into variables.  For example:

dim firstname as string
dim lastname as string.

<Get String>

firstname = Strsub(stringname, 1, 20) -- where "1" is where it starts and "20" is the length.
lastname = strsub(stringname, 21, 40) -- where "21" is where it starts and "40" is the length.
.
.
.

I'm sure this is really simple but the book I have doesn't make it clear.

chris
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, last name is 40 characters long....

Dim First As String = stringname.Substring(0, 20)
Dim Last As String = stringname.Substring(20, 40)
If you use this there HAS to be a space b/w the first and last name and there can't be more than one space in the string (ie. John J Smith)...
Dim saName as String() = stringname.Split(' ')
 
saName(0) will be your first name
saName(1) will be your last

Open in new window