Solved

Probably the Easiest String Question Ever

Posted on 2007-11-20
3
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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