Solved

substring in vbscript

Posted on 1997-11-10
1
2,662 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
ID: 1273344
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

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

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 demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

828 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