Board index » Visual Studio » Special Character's in a string Compare

Special Character's in a string Compare

Visual Studio311
The below code compares a variable read from a registry string value. It

works fine except on the ElseIf Stastement. I believe it is because my

string I am using to compare with has parenthesis in it. I know that there

is an occurance of this string with parenthesis in it. So my question is,

how can I write the code to accept them literally or, is there a way to

reduce this to a single IF statement and use a wildcard?



If strVal = "server.test.com" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

ElseIf strVal = "server.test.com(1)" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

End If


-
 

Re:Special Character's in a string Compare

Watch for line wrap (each Case .. statement should be on one line)



Select Case lcase(strVal)

Case "server.test.com": Wscript.Echo "Value Name: " & =

arrValueNames(x)&" =3D " & strVal

Case "server.test.com(1)": Wscript.Echo "Value Name: " & =

arrValueNames(x)&" =3D " & strVal

Case Else: Wscript.Echo "Value Name: " & arrValueNames(x)&" =3D " & =

strVal

End Select



--=20

Regards



Steven Burn

Ur I.T. Mate Group

www.it-mate.co.uk



Keeping it FREE!



"Yogi_Bear_79" <IThankU@spamfree.com>wrote in message =

Quote
The below code compares a variable read from a registry string value. =

It

works fine except on the ElseIf Stastement. I believe it is because my

string I am using to compare with has parenthesis in it. I know that =

there

is an occurance of this string with parenthesis in it. So my question =

is,

how can I write the code to accept them literally or, is there a way =

to

reduce this to a single IF statement and use a wildcard?

=20

If strVal =3D "server.test.com" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" =3D " & strVal

ElseIf strVal =3D "server.test.com(1)" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" =3D " & strVal

End If

=20

=20



-

Re:Special Character's in a string Compare

Steve,



Thanks, however the results are the same. The syntax of the Case

statement and the If statement are the same. In your example the only way

the string with the (1) is shown is in the Case Else statement.

Unfortunately there are other possibilities that I must exclude, that is why

I am looking for onf those two exact strings. Any other ideas?









"Steven Burn" <somewhere@in-time.invalid>wrote in message

Watch for line wrap (each Case .. statement should be on one line)



Select Case lcase(strVal)

Case "server.test.com": Wscript.Echo "Value Name: " & arrValueNames(x)&"

= " & strVal

Case "server.test.com(1)": Wscript.Echo "Value Name: " &

arrValueNames(x)&" = " & strVal

Case Else: Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

End Select



--

Regards



Steven Burn

Ur I.T. Mate Group

www.it-mate.co.uk



Keeping it FREE!



"Yogi_Bear_79" <IThankU@spamfree.com>wrote in message

Quote
The below code compares a variable read from a registry string value. It

works fine except on the ElseIf Stastement. I believe it is because my

string I am using to compare with has parenthesis in it. I know that

there

is an occurance of this string with parenthesis in it. So my question is,

how can I write the code to accept them literally or, is there a way to

reduce this to a single IF statement and use a wildcard?



If strVal = "server.test.com" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

ElseIf strVal = "server.test.com(1)" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

End If









-

Re:Special Character's in a string Compare

Hi,



"Yogi_Bear_79" <IThankU@spamfree.com>wrote in message

Quote
The below code compares a variable read from a registry string value. It

works fine except on the ElseIf Stastement. I believe it is because my

string I am using to compare with has parenthesis in it. I know that

there

is an occurance of this string with parenthesis in it. So my question is,

how can I write the code to accept them literally or, is there a way to

reduce this to a single IF statement and use a wildcard?



If strVal = "server.test.com" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

ElseIf strVal = "server.test.com(1)" Then

Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

End If





If I understand your question correctly --



String comparisons are literal. strVal = "server.test.com(1)" will be

compared literally. Parentheses inside quotes or in an assigned string

value are compared just like any other character. You need to use regular

expressions for a wildcard option.



Could you have whitespace or a casing issue in the strVal value? Try



lcase(trim(strVal)) = "server.test.com(1)"



or



lcase(replace(strVal, " ", "")) = "server.test.com(1)"



To verify your data, you might try substituting for the ElseIf lines



Else wscript.echo """" & strVal & """"



just to see what you've got. If you have an On Error Statement in the

script, you might try commenting it out, to make sure that you're not

throwing a runtime error with the array element concatenation.



Joe Earnest





-

Re:Special Character's in a string Compare



"Joe Earnest" <jearnest3-SPAM@earthlink.net>wrote in message

Quote
Hi,



"Yogi_Bear_79" <IThankU@spamfree.com>wrote in message

news:v8OdnaVImeunKMLfRVn-3Q@comcast.com...

>The below code compares a variable read from a registry string value.

It

>works fine except on the ElseIf Stastement. I believe it is because my

>string I am using to compare with has parenthesis in it. I know that

>there

>is an occurance of this string with parenthesis in it. So my question

is,

>how can I write the code to accept them literally or, is there a way to

>reduce this to a single IF statement and use a wildcard?

>

>If strVal = "server.test.com" Then

>Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

>ElseIf strVal = "server.test.com(1)" Then

>Wscript.Echo "Value Name: " & arrValueNames(x)&" = " & strVal

>End If

>



If I understand your question correctly --



String comparisons are literal. strVal = "server.test.com(1)" will be

compared literally. Parentheses inside quotes or in an assigned string

value are compared just like any other character. You need to use regular

expressions for a wildcard option.



Could you have whitespace or a casing issue in the strVal value? Try



lcase(trim(strVal)) = "server.test.com(1)"



or



lcase(replace(strVal, " ", "")) = "server.test.com(1)"



To verify your data, you might try substituting for the ElseIf lines



Else wscript.echo """" & strVal & """"



just to see what you've got. If you have an On Error Statement in the

script, you might try commenting it out, to make sure that you're not

throwing a runtime error with the array element concatenation.



Joe Earnest





I took a while but i finally caught it. there was a space between .com and

the ( character

"server.test.com (1)"





-