|
-
Jul 2nd, 2002, 04:02 AM
#1
Thread Starter
Member
String Comparison Question.
Hi,
I have 2 string
*************************
dim a as string
dim b as string
a="cat"
b="cat"
***************************
if i want to compare both the string to see whether they are the same.How do i compare ??
isit using
*****************************
if a=b then
msgbox "SAME"
else
msgbox "NOT SAME"
end if
***************************
is my way of doing wrong ?? not is there other way ?? thanks.
-
Jul 2nd, 2002, 04:06 AM
#2
-= B u g S l a y e r =-
that will work fine.
your sample is case sensitive. If you want Cat = caT then you can do like this
VB Code:
If UCase(a) = UCase(b) Then
MsgBox "SAME"
Else
MsgBox "NOT SAME"
End If
-
Jul 2nd, 2002, 04:06 AM
#3
PowerPoster
use the StrComp function
VB Code:
Dim a As String
Dim b As String
a = "cat"
b = "cAt"
If StrComp(a, b, vbBinaryCompare) = 0 Then
MsgBox "match"
Else
MsgBox "Unmatch"
End If
if the a dn b is not case sensitive, then compare with vbTextCompare as
VB Code:
Dim a As String
Dim b As String
a = "cat"
b = "cat"
If StrComp(a, b, vbTextCompare) = 0 Then
MsgBox "match"
Else
MsgBox "Unmatch"
End If
-
Jul 2nd, 2002, 04:09 AM
#4
Thread Starter
Member
OO thanks for all your reply
But, even if my string a is "CAT" and the other is "cat"
by using
if a=b then
msgbox "SAME"
else
msgbox "NOT SAME"
end if
i will get the msgbox "SAME" why ?? is it not case sensitive ??
-
Jul 2nd, 2002, 04:13 AM
#5
PowerPoster
it will return "NOT SAME"
-
Jul 2nd, 2002, 04:47 AM
#6
Thread Starter
Member
hmm, can i use "=" to compare 2 string ?? will it be accurate ??
-
Jul 2nd, 2002, 05:17 AM
#7
PowerPoster
it should be safe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|