?
Solved

Probably the Easiest String Question Ever

Posted on 2007-11-20
3
Medium Priority
?
156 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:clebo99
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 20322540
It's zero based, but you can use the substring method of the string class.

Dim First As String = stringname.Substring(0, 20)
Dim Last As String = stringname.Substring(20, 20)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20322550
Sorry, last name is 40 characters long....

Dim First As String = stringname.Substring(0, 20)
Dim Last As String = stringname.Substring(20, 40)
0
 
LVL 11

Expert Comment

by:DotNetThinker
ID: 20322757
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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question