Quality is delighting customers
write a program to
compare 2 strings using 'instr' function using vb script
Tags:
Permalink Reply by PINKESH SHARMA on July 24, 2012 at 2:19pm <!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
string1="Hi"
string2="Hello"
document.write(InStr(string1,string2))
</script>
</body>
</html>
Permalink Reply by ^ siva kumar @ on July 24, 2012 at 2:58pm ur checking one string is available in another string . I wanna compare and confirm same or not
Permalink Reply by rosanara begum on July 24, 2012 at 2:25pm 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
Permalink Reply by ^ siva kumar @ on July 24, 2012 at 2:58pm ur checking one string is available in another string . I wanna compare and confirm same or not
Permalink Reply by ^ siva kumar @ on July 24, 2012 at 2:59pm my requirement is both strings are same or not using instr function
Permalink Reply by Akhalesh Yadav on July 24, 2012 at 4:14pm you can use this function as
a=Instr(1,"Akhalesh Yadav","les")
msgbox a
'//output will be 5
Permalink Reply by Vaibhav Joshi on July 24, 2012 at 5:56pm Why don't you try http://www.w3schools.com/vbscript/func_instr.asp
Permalink Reply by pradeep dupaguntla on July 24, 2012 at 6:02pm <!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
string1="Hi"
string2="Hello"
document.write(InStr(string1,string2))
</script>
</body>
</html>
Permalink Reply by kotla lakshmi kanth reddy on July 24, 2012 at 7:02pm 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]
Permalink Reply by Vipin singh rawat on July 24, 2012 at 7:45pm 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
Manager QA at IdeaS Revenue Optimization
© 2013 Created by Quality Testing.