Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - compare strings

Reply
 
Old 12-20-2008   #1 (permalink)
WebNot


 
 

compare strings

Hi All
i am new to VB Script .... I need your help
Can any body tell me how i can i compare strings in VB Script right
know i am doing it using Javascript and it is working fine but i have
to do it in asp/VBscript the code for ref if here....



<script type="text/javascript">
var test1="hello,there,come,never,love,this,and,that,it,is,not,good";

var test1_array=test1.split(",");


var test2="good,never,come,there,love,is,that,it,and,hello";

var test2_array = test2.split(",");

var test1_Value;

var i=0, j = 0;

var found;

test1_Value ="";


for (i=0; i<=test1_array.length; i++)

{

found =0

for(j=0; j<=test2_array.length; j++)

{

if(test1_array[i] == test2_array[j])

{

found =1

}


}

if (found ==0 )

{

if (test1_Value == "")

{

test1_Value = test1_array[i]

}

else

{

test1_Value = test1_Value + "," + test1_array[i]

}


}

}

alert( test1_Value)

</script>

My System SpecsSystem Spec
Old 12-20-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: compare strings


"WebNot" <merajwani@xxxxxx> wrote in message
news:b24dd134-19af-478f-893a-503c6d2f8081@xxxxxx
Quote:

> Hi All
> i am new to VB Script .... I need your help
> Can any body tell me how i can i compare strings in VB Script right
> know i am doing it using Javascript and it is working fine but i have
> to do it in asp/VBscript the code for ref if here....
>
>
>
> <script type="text/javascript">
> var test1="hello,there,come,never,love,this,and,that,it,is,not,good";
>
> var test1_array=test1.split(",");
>
>
> var test2="good,never,come,there,love,is,that,it,and,hello";
>
> var test2_array = test2.split(",");
>
> var test1_Value;
>
> var i=0, j = 0;
>
> var found;
>
> test1_Value ="";
>
>
> for (i=0; i<=test1_array.length; i++)
>
> {
>
> found =0
>
> for(j=0; j<=test2_array.length; j++)
>
> {
>
> if(test1_array[i] == test2_array[j])
>
> {
>
> found =1
>
> }
>
>
> }
>
> if (found ==0 )
>
> {
>
> if (test1_Value == "")
>
> {
>
> test1_Value = test1_array[i]
>
> }
>
> else
>
> {
>
> test1_Value = test1_Value + "," + test1_array[i]
>
> }
>
>
> }
>
> }
>
> alert( test1_Value)
>
> </script>
I think I can read the java script. My interpretation follows:
============
Option Explicit
Dim strTest1, strTest2, arrTest1, arrTest2, i, j, blnFound, strResult

strTest1 = "hello,there,come,never,love,this,and,that,is,not,good"
arrTest1 = Split(strTest1, ",")
strTest2 = "good,never,come,there,love,is,that,it,and,hello"
arrTest2 = Split(strTest2, ",")
strResult = ""
For i = 0 To UBound(arrTest1)
blnFound = False
For j = 0 To UBound(arrTest2)
If (arrTest1(i) = arrTest2(j)) Then
blnFound = True
End If
Next
If (blnFound = False) Then
If (strResult = "") Then
strResult = arrTest1(i)
Else
strResult = strResult & "," & arrTest1(i)
End If
End If
Next
Wscript.Echo strResult
=======
When I run the above I get:

this,not

Is this what you intend?
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 12-20-2008   #3 (permalink)
Jim de Graff


 
 

Re: compare strings

s1 = "this is a string"
s2 = "This IS Another string"

You can compare s1 and s2 in different ways (case sensitive) by

if s1 = s2 then
if s1 < s2
if s1 > s2
if s1 <= s2

etc

Or you can use the StrComp function

StrComp(s1,s2)
StrComp(s1,s2,compare)

The function compares s1 to s2 and returns -1 if s1 < s2, 0 if s1 = s2 and
+1 id s1 > s2. The first form of the function is case sensitive ("a" is not
equal to "A"). It also returns null if either string is null. If you use the
second form you can specify compare as

vbBinaryCompare (case sensitive)
vbTextCompare (case insensitive - "a" equals "A")

example

select case StrComp(s1,s2,vbTextCompare)
case -1: wscript.echo "s1 < s2"
case 0 : wscript.echo "s1 = s2"
case 1 : wscript.echo "s1 > s2"
case null: wscript.echo "s1 or s2 is null"
end select



"WebNot" <merajwani@xxxxxx> wrote in message
news:b24dd134-19af-478f-893a-503c6d2f8081@xxxxxx
Quote:

> Hi All
> i am new to VB Script .... I need your help
> Can any body tell me how i can i compare strings in VB Script right
> know i am doing it using Javascript and it is working fine but i have
> to do it in asp/VBscript the code for ref if here....
>
>
>
> <script type="text/javascript">
> var test1="hello,there,come,never,love,this,and,that,it,is,not,good";
>
> var test1_array=test1.split(",");
>
>
> var test2="good,never,come,there,love,is,that,it,and,hello";
>
> var test2_array = test2.split(",");
>
> var test1_Value;
>
> var i=0, j = 0;
>
> var found;
>
> test1_Value ="";
>
>
> for (i=0; i<=test1_array.length; i++)
>
> {
>
> found =0
>
> for(j=0; j<=test2_array.length; j++)
>
> {
>
> if(test1_array[i] == test2_array[j])
>
> {
>
> found =1
>
> }
>
>
> }
>
> if (found ==0 )
>
> {
>
> if (test1_Value == "")
>
> {
>
> test1_Value = test1_array[i]
>
> }
>
> else
>
> {
>
> test1_Value = test1_Value + "," + test1_array[i]
>
> }
>
>
> }
>
> }
>
> alert( test1_Value)
>
> </script>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
non expandable here strings PowerShell
How to extract sub-strings? VB Script
question regarding strings PowerShell
Resource strings PowerShell
working with strings PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46