String part II - Thank you.
Author Message String part II - Thank you.

I have a string :

String = "+12+1234+123+1+23"           '+ sign is my break point between the
numbers. Number of integers between +'s can be different.

How can I break it down and assign to variables to get:

strA = 0012
strB = 1234
strC = 0123
strD = 0001
strE = 0023

I always want to have 4 digits (zeros as leading numbers)
Thanks for help.

Thu, 19 Dec 2002 03:00:00 GMT  String part II - Thank you.
I strongly suspect there are better ways to do this but this will work.  I
wasn't sure how many variables you would ultimately use and how they were to
be output so I just presented a message box for the case where you use four

----------------
Dim String, Number
String=InputBox("Enter the string with plus separators")
If Left(String,1)="+" Then
String=Right(String,(Len(String)-1))
End If
Number=split(String,"+")
Top=UBound(Number)
N=0
Do Until N=Top+1
If Len(Number(N))=3 Then
Number(N)=("0"&Number(N))
Else If Len(Number(N))=2 Then
Number(N)=("00"&Number(N))
Else If Len(Number(N))=1 Then
Number(N)=("000"&Number(N))
End If
End If
End If
N=N+1
Loop
MsgBox(Number(0)&vbCrLf&Number(1)&vbCrLf&Number(2)&_
vbCrLf&Number(3)&vbCrLf&Number(4))

---------------------

--
Steve Yandl

Quote:
> I have a string :

> String = "+12+1234+123+1+23"           '+ sign is my break point between
the
> numbers. Number of integers between +'s can be different.

> How can I break it down and assign to variables to get:

> strA = 0012
> strB = 1234
> strC = 0123
> strD = 0001
> strE = 0023

> I always want to have 4 digits (zeros as leading numbers)
> Thanks for help.

Thu, 19 Dec 2002 03:00:00 GMT  String part II - Thank you.
How about, for each number you have you try:

StrA = Right("000" & CStr(intNum), 4)

LFS

Quote:

> I have a string :

> String = "+12+1234+123+1+23"           '+ sign is my break point between the
> numbers. Number of integers between +'s can be different.

> How can I break it down and assign to variables to get:

> strA = 0012
> strB = 1234
> strC = 0123
> strD = 0001
> strE = 0023

> I always want to have 4 digits (zeros as leading numbers)
> Thanks for help.

Fri, 20 Dec 2002 03:00:00 GMT  String part II - Thank you.
The following would work with any number of number groups in the string -
held in an array for ease of use

HTH, Neil - UK

Option Explicit
Dim MyString, MyArray, Index
MyString = "+12+1234+123+1+123+1235+234+2341+999"

' Strip leading '+' if present otherwise first array element would be 0
If Left(MyString,1)="+" Then MyString=Mid(MyString,2)

' Split MyString using '+' as de-limiter, returning all instances,
performing a textual comparison
MyArray = Split(MyString,"+", -1 ,1)

' Work through array padding values with 0's
For Index=0 to Ubound(MyArray)
MyArray(Index)=Right("0000" & MyArray(Index),4)
WScript.Echo MyArray(Index)            ' Rem this line - display
purposes only
Next

Quote:
> I have a string :

> String = "+12+1234+123+1+23"           '+ sign is my break point between
the
> numbers. Number of integers between +'s can be different.

> How can I break it down and assign to variables to get:

> strA = 0012
> strB = 1234
> strC = 0123
> strD = 0001
> strE = 0023

> I always want to have 4 digits (zeros as leading numbers)
> Thanks for help.

Fri, 20 Dec 2002 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages