Solved

Probably the Easiest String Question Ever

Posted on 2007-11-20
3
146 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now