Solved

substring in vbscript

Posted on 1997-11-10
1
2,649 Views
Last Modified: 2008-03-10
I didn't find a vbscript section, but one certanly know it...
I want to extract a part of a string, let say: chars 1 to 4
of a 11 char strings, and also if possible to check if a char exist in a certan position...

let say that I read from a file a couple of lines like

 AAA=1292
 BBB=1291
 CCCCCC=1029

if I don't know in advance the lenght of the left side,
how can I do? I know how to read from a file, but not
how to deal with string functions...

0
Comment
Question by:jfbe
1 Comment
 
LVL 6

Accepted Solution

by:
tecbuilder earned 50 total points
Comment Utility
What it sounds like you are wanting to do is parse out the variable name and it's value.

You can use the InStr function to get the position of a certain character.  For example:  S = 'CCCCCC=1029'
thePosition = InStr(S,'=')
In this example, thePosition = 7.  If the '=' character would not have been found then thePosition = 0.

To get the length of the string use the Len function:
 Len(S, lenS)
where lenS is the number of characters of the string S which is 11.

Next to get the variable name and value associated with it use the Left and Right functions:
 varName = Left(S, thePosition-1) or Left(S, 6)
 varValue = Right(S, lenS-thePosition1) or Right(S, 4)

The Left function starts on the left side of the string and gets thePosition-1 characters.  The Right function starts on the right side of the string and gets the lenS-thePosition+1 characters.  
If you wanted to use just the Left function then you would have to chop up the string after each iteration so that the string only contained the characters that had not yet been checked.  This would be required if you were doing more than one parse sequence for the line.  For example:  
AAA=1234 BBB=5678 CCCCCC=3938

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

15 Experts available now in Live!

Get 1:1 Help Now