Solved

substring in vbscript

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

687 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