Quality Testing

Quality is delighting customers

Program to compare two strings using "instr" function using VB Script?

write a program to

compare 2 strings using 'instr' function using vb script

Views: 4958

Reply to This

Replies to This Discussion

<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">

string1="Hi"
string2="Hello"
document.write(InStr(string1,string2))

</script>
</body>

</html>

ur checking one string is available in another string . I wanna compare and confirm same or not

first you have to understand what is instr function then only you can able to write vb script code:

This function returns the string character position of a substring  in another string.

x=instr("Find the string position", "the")

this call returns 6

if not found this function returns 0

Hope i cleared your concept if anything let me know

Regards,

Rosanara 

ur checking one string is available in another string . I wanna compare and confirm same or not

my requirement is both strings are same or not using instr function

you can use this function as

a=Instr(1,"Akhalesh Yadav","les")

msgbox a

'//output will be 5

<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">

string1="Hi"
string2="Hello"
document.write(InStr(string1,string2))

</script>
</body>

</html>

 Hi,,

       consider the str1=REDDY , str2=REDDY  both strings are same...

 x=instr(1,"REDDY REDDY","k",1)

msgbox x   [Here we comparing both strings and  we are checking the string element "k" which is not in the string so get the output 0     ]

y=instr(1,"REDDY REDDY","e",1)

msgbox y  [Here also we comparing the strings but we are checking the string element "e" we get the output 2]

Hi ,you can use instr function as this to compare whether two strings are same or not.

Dim str1,Str2

Str1=inputbox("enter the string1")

str2=inputbox("enter the string2")

if instr(str1,str2) and instr(str2,str1) then

msgbox "Strings are same"

else

msgbox "string are not same"

End if

Thanks & Regards,

Vipin

Hi, can you please let me know what will be the output for only if statement

if instr(str1,str2) and instr(str2,str1) then ?

 

yes vipin singh is right

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service