substring method for VBScript

B

Bob Phillips

Use Mid$

MID$(string, start, len)

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
J

Jim Cone

VBA and VBS are not the same thing.
Which one are you referring to?
What does your "substr" method do?
What version of Excel do you use?
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


I've been searching for a substr method for VBScript. Is there one?
Thanks!
 
M

mechif

Hi!
I'm using Excel 2003 - writing a script with VBScript to read in data
from a CSV file.
One of the fields ("Client Name") will be used as the name of a
Worksheet and all the customer's info will be in the worksheet.
The field is free text, and sometimes contains illegal characters (for
Worksheet name) - *?[]\/ - and is sometimes too long.

Replace clientName, "*", "#"
Replace clientName, "\", "|"
Replace clientName, "/", "|"
Replace clientName, "?", "!"
Replace clientName, "[", "{"
Replace clientName, "]", "}"
If Len(clientName) > 30 Then
clientName = Substring(clientName, 1, 30)
End If

I don't think these rows work in VBScript...
Thanks for any help,
Mechi
 
J

Jim Cone

If you are using the Visual Basic Editor and not
the Microsoft Script Editor then try...

clientName = Replace(clientName, "*", "#")
clientName = Replace(clientName, "\", "|")
clientName = Replace(clientName, "/", "|")
clientName = Replace(clientName, "?", "!")
clientName = Replace(clientName, "[", "{")
clientName = Replace(clientName, "]", "}")
clientName = Left(clientName, 30)
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



<[email protected]>
wrote in message
Hi!
I'm using Excel 2003 - writing a script with VBScript to read in data
from a CSV file.
One of the fields ("Client Name") will be used as the name of a
Worksheet and all the customer's info will be in the worksheet.
The field is free text, and sometimes contains illegal characters (for
Worksheet name) - *?[]\/ - and is sometimes too long.

Replace clientName, "*", "#"
Replace clientName, "\", "|"
Replace clientName, "/", "|"
Replace clientName, "?", "!"
Replace clientName, "[", "{"
Replace clientName, "]", "}"
If Len(clientName) > 30 Then
clientName = Substring(clientName, 1, 30)
End If

I don't think these rows work in VBScript...
Thanks for any help,
Mechi
 
M

mechif

If you are using the Visual Basic Editor and not
the Microsoft Script Editor then try...

 clientName = Replace(clientName, "*", "#")
 clientName = Replace(clientName, "\", "|")
 clientName = Replace(clientName, "/", "|")
 clientName = Replace(clientName, "?", "!")
 clientName = Replace(clientName, "[", "{")
 clientName = Replace(clientName, "]", "}")
 clientName = Left(clientName, 30)
--
Jim Cone
Portland, Oregon  USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

<[email protected]>
wrote in message
Hi!
I'm using Excel 2003 - writing a script with VBScript to read in data
from a CSV file.
One of the fields ("Client Name") will be used as the name of a
Worksheet and all the customer's info will be in the worksheet.
The field is free text, and sometimes contains illegal characters (for
Worksheet name) - *?[]\/ - and is sometimes too long.

Replace clientName, "*", "#"
Replace clientName, "\", "|"
Replace clientName, "/", "|"
Replace clientName, "?", "!"
Replace clientName, "[", "{"
Replace clientName, "]", "}"
If Len(clientName) > 30 Then
clientName = Substring(clientName, 1, 30)
End If

I don't think these rows work in VBScript...
Thanks for any help,
Mechi

VBA and VBS are not the same thing.
Which one are you referring to?
What does your "substr" method do?
What version of Excel do you use?
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
I've been searching for a substr method for VBScript. Is there one?
Thanks!- Hide quoted text -

- Show quoted text -

It worked!!!
I'm using VBSedit (free version)
Thanks!
 
Joined
Jul 24, 2014
Messages
1
Reaction score
0
To retrieve a sub string or a number of characters from a string, "Mid" function can be used in VBScript.

**Syntax**:
Mid(String, [starting position of the sub-string], [length of sub-string])

**Example**:

Dim String1, strSub

String1 = "Unified Functional Testing"

strSub = Mid(String1, 9, 10)

The variable strSub would contain the sub-string "Functional".

Thanks,

Nivedita D

indiumsoft.com/core-qa-offerings/test-automation[/url]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top