Solved

substring in vbscript

Posted on 1997-11-10
1
2,659 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

772 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