How to convert string to Array in VB/VBScript

I have a string and I need to parse each chars to check if that chars is the
one I am looking for...looks simple ut not striking me at this moment....

I was planning to iterating the array to its length and find out the chars
by ASC function....

Re: string to array by McKirahan

McKirahan
Mon Jul 10 13:18:08 CDT 2006

"abcd" <abcd@abcd.com> wrote in message
news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
> How to convert string to Array in VB/VBScript
>
> I have a string and I need to parse each chars to check if that chars is
the
> one I am looking for...looks simple ut not striking me at this moment....
>
> I was planning to iterating the array to its length and find out the chars
> by ASC function....

Are you looking for one of these?

Dim a
a = Split(s,",")
Dim i
For i = 0 To UBound(a)
If a(i) = "your character test" Then ...
Next


If InStr(s,"your character test") > 0 Then ...


If not then provide more information.



Re: string to array by abcd

abcd
Mon Jul 10 13:22:48 CDT 2006

basically I will have input string in that I need to check if 2 chars are
uppercase, 2 chrs are lowercase and 2 chars are special chars and 2 chars
are numeric...



"McKirahan" <News@McKirahan.com> wrote in message
news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
> "abcd" <abcd@abcd.com> wrote in message
> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>> How to convert string to Array in VB/VBScript
>>
>> I have a string and I need to parse each chars to check if that chars is
> the
>> one I am looking for...looks simple ut not striking me at this moment....
>>
>> I was planning to iterating the array to its length and find out the
>> chars
>> by ASC function....
>
> Are you looking for one of these?
>
> Dim a
> a = Split(s,",")
> Dim i
> For i = 0 To UBound(a)
> If a(i) = "your character test" Then ...
> Next
>
>
> If InStr(s,"your character test") > 0 Then ...
>
>
> If not then provide more information.
>
>



Re: string to array by abcd

abcd
Mon Jul 10 13:27:56 CDT 2006

a = Split(s,",")

this statement didnt convert the string to an array of chars....

I get a(0) as the whole string value
there is no a(1).....a(n) values

"McKirahan" <News@McKirahan.com> wrote in message
news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
> "abcd" <abcd@abcd.com> wrote in message
> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>> How to convert string to Array in VB/VBScript
>>
>> I have a string and I need to parse each chars to check if that chars is
> the
>> one I am looking for...looks simple ut not striking me at this moment....
>>
>> I was planning to iterating the array to its length and find out the
>> chars
>> by ASC function....
>
> Are you looking for one of these?
>
> Dim a
> a = Split(s,",")
> Dim i
> For i = 0 To UBound(a)
> If a(i) = "your character test" Then ...
> Next
>
>
> If InStr(s,"your character test") > 0 Then ...
>
>
> If not then provide more information.
>
>



Re: string to array by ekkehard

ekkehard
Mon Jul 10 13:51:04 CDT 2006

abcd wrote:
> How to convert string to Array in VB/VBScript
>
There is a Split() function in VBScript; use the VBScript Docs to check
whether it is more suitable to your problem than splitting a string into
an array consisting of it's characters like this

Function splitToChrArr( sSrc )
ReDim aRVal( Len( sSrc ) - 1 )
Dim nIdx
For nIdx = 0 To UBound( aRVal )
aRVal( nIdx ) = Mid( sSrc, nIdx + 1, 1 )
Next
splitToChrArr = aRVal
End Function

or this

Function splitToChrArr( sSrc )
ReDim aRVal( Len( sSrc ) - 1 )
Dim nIdx
Dim oRE : Set oRE = New RegExp
oRE.Pattern = "[\s\S]"
oRE.Global = True
Dim oMTS : Set oMTS = oRE.Execute( sSrc )
For nIdx = 0 To (oMTS.Count - 1)
aRVal( nIdx ) = oMTS( nIdx ).Value
Next
splitToChrArr = aRVal
End Function

> I have a string and I need to parse each chars to check if that chars is the
> one I am looking for...looks simple ut not striking me at this moment....
>

Use Instr() or a RegExp to check whether a string contains "the one" char you
are looking for; use Split() to break it up into the parts separeted by this
char.

> I was planning to iterating the array to its length and find out the chars
> by ASC function....
>
Don't.

Re: string to array by Bob

Bob
Mon Jul 10 13:57:56 CDT 2006

Provide an example of the string you want to split into an array, a
description of how the string is delimited, and an illustration of the
array you wish to generate.

abcd wrote:
> a = Split(s,",")
>
> this statement didnt convert the string to an array of chars....
>
> I get a(0) as the whole string value
> there is no a(1).....a(n) values
>
> "McKirahan" <News@McKirahan.com> wrote in message
> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
>> "abcd" <abcd@abcd.com> wrote in message
>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>>> How to convert string to Array in VB/VBScript
>>>
>>> I have a string and I need to parse each chars to check if that
>>> chars is the one I am looking for...looks simple ut not striking me
>>> at this moment....
>>>
>>> I was planning to iterating the array to its length and find out the
>>> chars
>>> by ASC function....
>>
>> Are you looking for one of these?
>>
>> Dim a
>> a = Split(s,",")
>> Dim i
>> For i = 0 To UBound(a)
>> If a(i) = "your character test" Then ...
>> Next
>>
>>
>> If InStr(s,"your character test") > 0 Then ...
>>
>>
>> If not then provide more information.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: string to array by abcd

abcd
Mon Jul 10 14:08:45 CDT 2006

input string "abcdefg"

how can I convert this string into array so that I get the values

dim a

a(0) ="a"
a(0) ="a"
a(0) ="a"
a(0) ="a"
a(0) ="a"



"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
> Provide an example of the string you want to split into an array, a
> description of how the string is delimited, and an illustration of the
> array you wish to generate.
>
> abcd wrote:
>> a = Split(s,",")
>>
>> this statement didnt convert the string to an array of chars....
>>
>> I get a(0) as the whole string value
>> there is no a(1).....a(n) values
>>
>> "McKirahan" <News@McKirahan.com> wrote in message
>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
>>> "abcd" <abcd@abcd.com> wrote in message
>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>>>> How to convert string to Array in VB/VBScript
>>>>
>>>> I have a string and I need to parse each chars to check if that
>>>> chars is the one I am looking for...looks simple ut not striking me
>>>> at this moment....
>>>>
>>>> I was planning to iterating the array to its length and find out the
>>>> chars
>>>> by ASC function....
>>>
>>> Are you looking for one of these?
>>>
>>> Dim a
>>> a = Split(s,",")
>>> Dim i
>>> For i = 0 To UBound(a)
>>> If a(i) = "your character test" Then ...
>>> Next
>>>
>>>
>>> If InStr(s,"your character test") > 0 Then ...
>>>
>>>
>>> If not then provide more information.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>



Re: string to array by abcd

abcd
Mon Jul 10 14:09:32 CDT 2006

input string "abcdefg"

how can I convert this string into array so that I get the values

dim a

a(0) ="a"
a(1) ="b"
a(2) ="c"
a(3) ="d"
a(4) ="e"
a(5) ="f"
a(6) ="g"



"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
> Provide an example of the string you want to split into an array, a
> description of how the string is delimited, and an illustration of the
> array you wish to generate.
>
> abcd wrote:
>> a = Split(s,",")
>>
>> this statement didnt convert the string to an array of chars....
>>
>> I get a(0) as the whole string value
>> there is no a(1).....a(n) values
>>
>> "McKirahan" <News@McKirahan.com> wrote in message
>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
>>> "abcd" <abcd@abcd.com> wrote in message
>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>>>> How to convert string to Array in VB/VBScript
>>>>
>>>> I have a string and I need to parse each chars to check if that
>>>> chars is the one I am looking for...looks simple ut not striking me
>>>> at this moment....
>>>>
>>>> I was planning to iterating the array to its length and find out the
>>>> chars
>>>> by ASC function....
>>>
>>> Are you looking for one of these?
>>>
>>> Dim a
>>> a = Split(s,",")
>>> Dim i
>>> For i = 0 To UBound(a)
>>> If a(i) = "your character test" Then ...
>>> Next
>>>
>>>
>>> If InStr(s,"your character test") > 0 Then ...
>>>
>>>
>>> If not then provide more information.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>




Re: string to array by Bob

Bob
Mon Jul 10 14:58:08 CDT 2006

Since there are no delimiters, you are forced to loop through the
string:
dim s, a(), x, i
s="abcdefg"
x=len(s) - 1
redim a(x)
for i = 0 to x
a(i) = mid(s,i,1)
next


abcd wrote:
> input string "abcdefg"
>
> how can I convert this string into array so that I get the values
>
> dim a
>
> a(0) ="a"
> a(1) ="b"
> a(2) ="c"
> a(3) ="d"
> a(4) ="e"
> a(5) ="f"
> a(6) ="g"
>
>
>
> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
>> Provide an example of the string you want to split into an array, a
>> description of how the string is delimited, and an illustration of
>> the array you wish to generate.
>>
>> abcd wrote:
>>> a = Split(s,",")
>>>
>>> this statement didnt convert the string to an array of chars....
>>>
>>> I get a(0) as the whole string value
>>> there is no a(1).....a(n) values
>>>
>>> "McKirahan" <News@McKirahan.com> wrote in message
>>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
>>>> "abcd" <abcd@abcd.com> wrote in message
>>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>>>>> How to convert string to Array in VB/VBScript
>>>>>
>>>>> I have a string and I need to parse each chars to check if that
>>>>> chars is the one I am looking for...looks simple ut not striking
>>>>> me at this moment....
>>>>>
>>>>> I was planning to iterating the array to its length and find out
>>>>> the chars
>>>>> by ASC function....
>>>>
>>>> Are you looking for one of these?
>>>>
>>>> Dim a
>>>> a = Split(s,",")
>>>> Dim i
>>>> For i = 0 To UBound(a)
>>>> If a(i) = "your character test" Then ...
>>>> Next
>>>>
>>>>
>>>> If InStr(s,"your character test") > 0 Then ...
>>>>
>>>>
>>>> If not then provide more information.
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: string to array by Justin

Justin
Mon Jul 10 16:25:53 CDT 2006

On Mon, 10 Jul 2006 13:22:48 -0500, abcd <abcd@abcd.com> wrote:
> basically I will have input string in that I need to check if 2 chars are
> uppercase, 2 chrs are lowercase and 2 chars are special chars and 2 chars
> are numeric...

You can use a regular expression to check for them. You didn't specify
which characters were special, so I chose a few of personal significance
on your behalf. :)

Option Explicit

Dim tests, i
tests = Array("ValiD!!00", _
"00!!DilaV", _
"nouppercase!!00", _
"NOLOWERCASE!!00", _
"NOspecial00", _
"NOnumeric!!")
For i = 0 To UBound(tests) : WScript.Echo Validate(tests(i)) : Next

Dim [Validate::UpperCase]
Dim [Validate::LowerCase]
Dim [Validate::Numeric]
Dim [Validate::Special]
Function Validate(password)
If IsEmpty([Validate::UpperCase]) Then
Set [Validate::UpperCase] = New RegExp
[Validate::UpperCase].Pattern = "(?:.*[A-Z]){2}"
End If
If IsEmpty([Validate::LowerCase]) Then
Set [Validate::LowerCase] = New RegExp
[Validate::LowerCase].Pattern = "(?:.*[a-z]){2}"
End If
If IsEmpty([Validate::Numeric]) Then
Set [Validate::Numeric] = New RegExp
[Validate::Numeric].Pattern = "(?:.*\d){2}"
End If
If IsEmpty([Validate::Special]) Then
Set [Validate::Special] = New RegExp
[Validate::Special].Pattern = "(?:.*[!@#$%^&*()]){2}"
End If

If [Validate::UpperCase].Test(password) And _
[Validate::LowerCase].Test(password) And _
[Validate::Numeric]. Test(password) And _
[Validate::Special]. Test(password) Then
Validate = "[pass] " & password
Else
Validate = "[fail] " & password
End If
End Function


As an aside, I initially tried to do this in one expression with
look-aheads, but found it hanged or crashed the script engine. I included
that version below, so if anyone knows of a work-around, I'd be pleased to
hear it.

Dim [Validate::re]
Const [Validate::UpperCase] = "(?=(?:.*[A-Z]){2})"
Const [Validate::LowerCase] = "(?=(?:.*[a-z]){2})"
Const [Validate::Numeric] = "(?=(?:.*\d){2})"
Const [Validate::Special] = "(?=(?:.*[^!@#$%^&*()]){2})"
Function Validate(password)

If IsEmpty([Validate::re]) Then
Set [Validate::re] = New RegExp
[Validate::re].Pattern = [Validate::UpperCase] _
& [Validate::LowerCase] _
& [Validate::Numeric] _
& [Validate::Special]
End If

If [Validate::re].Test(password) Then
Validate = "[pass] " & password
Else
Validate = "[fail] " & password
End If
End Function

--
Justin Piper
Bizco Technologies
http://www.bizco.com/

Re: string to array by Tom

Tom
Mon Jul 10 16:46:11 CDT 2006

Wait. What am I missing. If the OP wants to find if a character
resides in a string, why not use the InStr() method? This approach
also provides the position of that character in the string. If
multiple occurrences are expected and their positions desired, a search
could be done something like this ...

s="abcdefgabcdefg"
cSearch = "d"

nPosition = InStr(s, cSearch)
if nPosition = 0 then
sOutput = "The character was not found in the string."
else
sOutput = "The character was found." _
& vbNewline & "The occurrence(s) is(are) at: "
Do
sOutput = sOutput & " " & nPosition
nPosition = InStr(nPosition + 1, s, cSearch)
Loop until nPosition = 0
end if
msgbox sOutput

Tom Lavedas
=============
http://members.cox.net/tglbatch/wsh

Bob Barrows [MVP] wrote:
> Since there are no delimiters, you are forced to loop through the
> string:
> dim s, a(), x, i
> s="abcdefg"
> x=len(s) - 1
> redim a(x)
> for i = 0 to x
> a(i) = mid(s,i,1)
> next
>
>
> abcd wrote:
> > input string "abcdefg"
> >
> > how can I convert this string into array so that I get the values
> >
> > dim a
> >
> > a(0) ="a"
> > a(1) ="b"
> > a(2) ="c"
> > a(3) ="d"
> > a(4) ="e"
> > a(5) ="f"
> > a(6) ="g"
> >
> >
> >
> > "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> > news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
> >> Provide an example of the string you want to split into an array, a
> >> description of how the string is delimited, and an illustration of
> >> the array you wish to generate.
> >>
> >> abcd wrote:
> >>> a = Split(s,",")
> >>>
> >>> this statement didnt convert the string to an array of chars....
> >>>
> >>> I get a(0) as the whole string value
> >>> there is no a(1).....a(n) values
> >>>
> >>> "McKirahan" <News@McKirahan.com> wrote in message
> >>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
> >>>> "abcd" <abcd@abcd.com> wrote in message
> >>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
> >>>>> How to convert string to Array in VB/VBScript
> >>>>>
> >>>>> I have a string and I need to parse each chars to check if that
> >>>>> chars is the one I am looking for...looks simple ut not striking
> >>>>> me at this moment....
> >>>>>
> >>>>> I was planning to iterating the array to its length and find out
> >>>>> the chars
> >>>>> by ASC function....
> >>>>
> >>>> Are you looking for one of these?
> >>>>
> >>>> Dim a
> >>>> a = Split(s,",")
> >>>> Dim i
> >>>> For i = 0 To UBound(a)
> >>>> If a(i) = "your character test" Then ...
> >>>> Next
> >>>>
> >>>>
> >>>> If InStr(s,"your character test") > 0 Then ...
> >>>>
> >>>>
> >>>> If not then provide more information.
> >>
> >> --
> >> Microsoft MVP -- ASP/ASP.NET
> >> Please reply to the newsgroup. The email account listed in my From
> >> header is my spam trap, so I don't check it very often. You will get
> >> a quicker response by posting to the newsgroup.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.


Re: string to array by Bob

Bob
Mon Jul 10 17:32:27 CDT 2006

I was just answering the question, which was how to turn that string into an
array. I'm still not clear about why he wants to do it.

Earlier responses had mentioned using InStr(), and since abcd kept asking, I
assumed InStr() was not the answer he was looking for.

Tom Lavedas wrote:
> Wait. What am I missing. If the OP wants to find if a character
> resides in a string, why not use the InStr() method? This approach
> also provides the position of that character in the string. If
> multiple occurrences are expected and their positions desired, a
> search could be done something like this ...
>
> s="abcdefgabcdefg"
> cSearch = "d"
>
> nPosition = InStr(s, cSearch)
> if nPosition = 0 then
> sOutput = "The character was not found in the string."
> else
> sOutput = "The character was found." _
> & vbNewline & "The occurrence(s) is(are) at: "
> Do
> sOutput = sOutput & " " & nPosition
> nPosition = InStr(nPosition + 1, s, cSearch)
> Loop until nPosition = 0
> end if
> msgbox sOutput
>
> Tom Lavedas
> =============
> http://members.cox.net/tglbatch/wsh
>
> Bob Barrows [MVP] wrote:
>> Since there are no delimiters, you are forced to loop through the
>> string:
>> dim s, a(), x, i
>> s="abcdefg"
>> x=len(s) - 1
>> redim a(x)
>> for i = 0 to x
>> a(i) = mid(s,i,1)
>> next
>>
>>
>> abcd wrote:
>>> input string "abcdefg"
>>>
>>> how can I convert this string into array so that I get the values
>>>
>>> dim a
>>>
>>> a(0) ="a"
>>> a(1) ="b"
>>> a(2) ="c"
>>> a(3) ="d"
>>> a(4) ="e"
>>> a(5) ="f"
>>> a(6) ="g"
>>>
>>>
>>>
>>> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
>>> news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
>>>> Provide an example of the string you want to split into an array, a
>>>> description of how the string is delimited, and an illustration of
>>>> the array you wish to generate.
>>>>
>>>> abcd wrote:
>>>>> a = Split(s,",")
>>>>>
>>>>> this statement didnt convert the string to an array of chars....
>>>>>
>>>>> I get a(0) as the whole string value
>>>>> there is no a(1).....a(n) values
>>>>>
>>>>> "McKirahan" <News@McKirahan.com> wrote in message
>>>>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
>>>>>> "abcd" <abcd@abcd.com> wrote in message
>>>>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
>>>>>>> How to convert string to Array in VB/VBScript
>>>>>>>
>>>>>>> I have a string and I need to parse each chars to check if that
>>>>>>> chars is the one I am looking for...looks simple ut not striking
>>>>>>> me at this moment....
>>>>>>>
>>>>>>> I was planning to iterating the array to its length and find out
>>>>>>> the chars
>>>>>>> by ASC function....
>>>>>>
>>>>>> Are you looking for one of these?
>>>>>>
>>>>>> Dim a
>>>>>> a = Split(s,",")
>>>>>> Dim i
>>>>>> For i = 0 To UBound(a)
>>>>>> If a(i) = "your character test" Then ...
>>>>>> Next
>>>>>>
>>>>>>
>>>>>> If InStr(s,"your character test") > 0 Then ...
>>>>>>
>>>>>>
>>>>>> If not then provide more information.
>>>>
>>>> --
>>>> Microsoft MVP -- ASP/ASP.NET
>>>> Please reply to the newsgroup. The email account listed in my From
>>>> header is my spam trap, so I don't check it very often. You will
>>>> get a quicker response by posting to the newsgroup.
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



Re: string to array by Richard

Richard
Mon Jul 10 20:12:51 CDT 2006


"abcd" <abcd@abcd.com> wrote in message
news:e9D6ERFpGHA.4424@TK2MSFTNGP05.phx.gbl...
> input string "abcdefg"
>
> how can I convert this string into array so that I get the values
>
> dim a
>
> a(0) ="a"
> a(0) ="a"
> a(0) ="a"
> a(0) ="a"
> a(0) ="a"

There needs to be something to delimit elements in the string, a character
like "," or a space, or something. The Split(s, ",") function suggested
earler assumed the string had elements delimited by commas, such as the
string "a,b,c,abc,f,g". Otherwise, we have to assume that each element is a
single character, and parse the string for every character. For example, the
following takes the string s and creates the array arrValues:
============
Dim s, arrValues(), k

' Specify input string.
s = "abcdefg"

' Parse the string and create array.
For k = 0 To Len(s) -1
ReDim Preserve arrValues(k)
arrValues(k) = Mid(s, k + 1, 1)
Next

' Display array.
For k = 0 To UBound(arrValues)
Wscript.Echo "arrValues(" & CStr(k) & ") = " & arrValues(k)
Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
=============



Re: string to array by Tom

Tom
Mon Jul 10 22:45:05 CDT 2006

Like I said - I must have been missing something. I scanned earlier
responses, but missed the reference to Instr().

Tom Lavedas

Bob Barrows [MVP] wrote:
> I was just answering the question, which was how to turn that string into an
> array. I'm still not clear about why he wants to do it.
>
> Earlier responses had mentioned using InStr(), and since abcd kept asking, I
> assumed InStr() was not the answer he was looking for.
>
> Tom Lavedas wrote:
> > Wait. What am I missing. If the OP wants to find if a character
> > resides in a string, why not use the InStr() method? This approach
> > also provides the position of that character in the string. If
> > multiple occurrences are expected and their positions desired, a
> > search could be done something like this ...
> >
> > s="abcdefgabcdefg"
> > cSearch = "d"
> >
> > nPosition = InStr(s, cSearch)
> > if nPosition = 0 then
> > sOutput = "The character was not found in the string."
> > else
> > sOutput = "The character was found." _
> > & vbNewline & "The occurrence(s) is(are) at: "
> > Do
> > sOutput = sOutput & " " & nPosition
> > nPosition = InStr(nPosition + 1, s, cSearch)
> > Loop until nPosition = 0
> > end if
> > msgbox sOutput
> >
> > Tom Lavedas
> > =============
> > http://members.cox.net/tglbatch/wsh
> >
> > Bob Barrows [MVP] wrote:
> >> Since there are no delimiters, you are forced to loop through the
> >> string:
> >> dim s, a(), x, i
> >> s="abcdefg"
> >> x=len(s) - 1
> >> redim a(x)
> >> for i = 0 to x
> >> a(i) = mid(s,i,1)
> >> next
> >>
> >>
> >> abcd wrote:
> >>> input string "abcdefg"
> >>>
> >>> how can I convert this string into array so that I get the values
> >>>
> >>> dim a
> >>>
> >>> a(0) ="a"
> >>> a(1) ="b"
> >>> a(2) ="c"
> >>> a(3) ="d"
> >>> a(4) ="e"
> >>> a(5) ="f"
> >>> a(6) ="g"
> >>>
> >>>
> >>>
> >>> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> >>> news:%23njcCLFpGHA.756@TK2MSFTNGP05.phx.gbl...
> >>>> Provide an example of the string you want to split into an array, a
> >>>> description of how the string is delimited, and an illustration of
> >>>> the array you wish to generate.
> >>>>
> >>>> abcd wrote:
> >>>>> a = Split(s,",")
> >>>>>
> >>>>> this statement didnt convert the string to an array of chars....
> >>>>>
> >>>>> I get a(0) as the whole string value
> >>>>> there is no a(1).....a(n) values
> >>>>>
> >>>>> "McKirahan" <News@McKirahan.com> wrote in message
> >>>>> news:ltadnRAX6_B9BC_ZnZ2dnUVZ_qqdnZ2d@comcast.com...
> >>>>>> "abcd" <abcd@abcd.com> wrote in message
> >>>>>> news:uLaVerEpGHA.3936@TK2MSFTNGP04.phx.gbl...
> >>>>>>> How to convert string to Array in VB/VBScript
> >>>>>>>
> >>>>>>> I have a string and I need to parse each chars to check if that
> >>>>>>> chars is the one I am looking for...looks simple ut not striking
> >>>>>>> me at this moment....
> >>>>>>>
> >>>>>>> I was planning to iterating the array to its length and find out
> >>>>>>> the chars
> >>>>>>> by ASC function....
> >>>>>>
> >>>>>> Are you looking for one of these?
> >>>>>>
> >>>>>> Dim a
> >>>>>> a = Split(s,",")
> >>>>>> Dim i
> >>>>>> For i = 0 To UBound(a)
> >>>>>> If a(i) = "your character test" Then ...
> >>>>>> Next
> >>>>>>
> >>>>>>
> >>>>>> If InStr(s,"your character test") > 0 Then ...
> >>>>>>
> >>>>>>
> >>>>>> If not then provide more information.
> >>>>
> >>>> --
> >>>> Microsoft MVP -- ASP/ASP.NET
> >>>> Please reply to the newsgroup. The email account listed in my From
> >>>> header is my spam trap, so I don't check it very often. You will
> >>>> get a quicker response by posting to the newsgroup.
> >>
> >> --
> >> Microsoft MVP -- ASP/ASP.NET
> >> Please reply to the newsgroup. The email account listed in my From
> >> header is my spam trap, so I don't check it very often. You will get
> >> a quicker response by posting to the newsgroup.
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"