Solved

Probably the Easiest String Question Ever

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IDE for Python 5 104
Win 10 Automation Error with .doCmd in Access 2 86
SSIS Column mapping 5 40
Excel Macro: Correct Macro that creates tabs for each "AccountSku" 4 47
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

737 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