Cutting strings in VBScript

Results 1 to 4 of 4

Thread: Cutting strings in VBScript

  1. #1
    Mandi Guest

    Default Cutting strings in VBScript

    We have a string that currently looks like this:<BR><BR>1.1.2 & 2.1.3 &...............<BR><BR>and we woule like to extract e.g. 1.1.2 and then 2.1.3 etc. etc<BR><BR>how is this done in VBScript or could we do it in Javascript and then read the values in VBScript?

  2. #2
    Join Date
    Dec 1969

    Default RE: Cutting strings in VBScript

    You will need to write a function that loops while there is &#039&&#039 in the string and cuts out the bits in between.<BR><BR>the VBScript functions you will need are :<BR><BR>- inStr &#039returns a positive long if found in string<BR>i.e pos1 = inStr(str,"&") &#039 will return position of first & (=7)<BR> pos2 = inStr(str,pos1+1,"&")&#039will return pos of second &(=15) <BR> &#039 it starts looking from position of the first<BR>- Mid<BR>i.e value1 = Mid(str,1,pos1-2) &#039will set value1 = "1.1.2"<BR> &#039cuts string between (string,start,finish)<BR> &#039 if a finish position is not specified goes to end of string <BR><BR>you will need to make a while inStr(str,startpos,"&") loop to cycle through the string and set the startpos to each instance of & as it loops through the string.

  3. #3
    Mandi Guest

    Default RE: Cutting strings in VBScript

    Thanks you are a saviour

  4. #4
    Tobey Unruh Guest

    Default RE: Cutting strings in VBScript

    You mean that worked?? Why don&#039t you just use split? It is ten times easier.<BR><BR>MyString = "1.1.1 & 1.1.2 & 1.1.3"<BR><BR>NewString = Split(MyString, "&", -1)<BR><BR>NewString is now an array containing each element:<BR><BR>NewString(0) = "1.1.1"<BR>NewString(1) = "1.1.2"<BR>NewString(2) = "1.1.3"<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts