Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

substring in vbscript

Posted on 1997-11-10
1
Medium Priority
?
2,674 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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

810 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