Active Server Pages: Compare strings, find position
Basics
Compare two strings for similarity
Find position of a substrings within a string
Is a substrings within a string?
Find position of a substrings within a string after skipping part of the string
 
 


Basics

Code
<pre>
AA="My friend John is from Cuba"
BB="John"

<% AA="My friend John is from Cuba"
BB="John" %>
Is BB a substring of AA?(case sensitive)
<% if inStr (AA,BB)=0 then 
Response.write ("Yes") 
else
Response.write ("No") 
End if %>

In which position is located BB withing AA?(case sensitive)
<% =InStr (AA,BB) %> (value will be 0 in case BB is not a substring of AA)
</pre>

Resulting page
AA="john"
BB="John"
 

Is BB a substring of AA?(case sensitive)
No

In which position is located BB withing AA?(case sensitive)
11 (value will be 0 in case BB is not a substring of AA)

Compare two strings for similarity
Code
<pre>
AA="john"
BB="John"

<% AA="john"
BB="John" %>
Are AA and BB the same string?(case sensitive)
<% if StrComp (AA,BB,0)=0 then 
Response.write ("Yes") 
else
Response.write ("No") 
End if %>

Are AA and BB the same string?( no case sensitive)
<% if StrComp (AA,BB,1)=0 then 
Response.write ("Yes") 
else
Response.write ("No") 
End if %>
</pre>

Resulting page
AA="john"
BB="John"
 

Are AA and BB the same string?(case sensitive)
No

Are AA and BB the same string?(no case sensitive)
Yes

Find position of a substrings within a string

Code
<pre>
AA="12345a6789"
BB="345A"

<% AA="12345a6789"
BB="345A" %>
Which is the starting position of string BB  within AA?(case sensitive)
<% if InStr (1,AA,BB,0)=0 then 
Response.write ("BB is not a substring of AA") 
else
Response.write (InStr (1,AA,BB,0)) 
End if %>

Which is the starting position of string BB  within AA?(no case sensitive)
<% if InStr (1,AA,BB,1)=0 then 
Response.write ("BB is not a substring of AA") 
else
Response.write (InStr (1,AA,BB,1)) 
End if %>
</pre>

Resulting page
AA="12345a6789"
BB="345A"
 

Which is the starting position of string BB  within AA?(case sensitive)
BB is not a substring of AA

Which is the starting position of string BB  within AA?(no case sensitive)
3

Is a substrings within a string?

Code
<pre>
AA="the cat is nice"
BB="Cat"

<% AA="the cat is nice"
BB="Cat" %>
Is BB a substring of AA?(case sensitive)
<% if InStr (1,AA,BB,0)>0 then 
Response.write ("Yes") 
else
Response.write ("No") 
End if %>

Is BB a substring of AA?(no case sensitive)
<% if InStr (1,AA,BB,1)>0 then 
Response.write ("Yes") 
else
Response.write ("No") 
End if %>
</pre>

Resulting page
AA="the cat is nice"
BB="Cat"
 

Is BB a substring of AA?(case sensitive)
No

Is BB a substring of AA?(no case sensitive)
Yes

Find position of a substrings within a string after skipping part of the string

Code
<pre>

AA="12345A6789XXXXXX12345a678912345a678912345a6789
12345a678912345A6789"
BB="345A"
CC="345B"

<% AA="12345A6789XXXXXX12345a678912345a678912345a6789
12345a678912345A6789"
BB="345A" 
CC="345B" %>
I know BB is included in the first 9 positions of AA, but it is included in the rest of the string?(case sensitive)
<% if InStr (9,AA,BB,0)=0 then 
Response.write ("BB is not a substring of AA after position 9") 
else
Response.write ("BB is present in String AA after position 9. Its position is ") 
Response.write (InStr (9,AA,BB,0)) 
End if %>

I know BB is included in the first 9 positions of AA, but it is included in the rest of the string?(no case sensitive)
<% if InStr (9,AA,BB,1)=0 then 
Response.write ("BB is not a substring of AA after position 9") 
else
Response.write ("BB is present in String AA after position 9. Its position is ")
Response.write (InStr (9,AA,BB,1)) 
End if %>

Is CC included in string AA after position 9?(no case sensitive)
<% if InStr (9,AA,CC,1)=0 then 
Response.write ("BB is not a substring of AA after position 9") 
else
Response.write ("BB is present in String AA after position 9. Its position is ")
Response.write (InStr (9,AA,CC,1)) 
End if %>
</pre>

Resulting page
AA="12345A6789XXXXXX12345a678912345a678912345a
678912345a678912345A6789"
BB="345A"
CC="345B"


I know BB is included in the first 9 positions of AA,
but it is included in the rest of the string?
(case sensitive) BB is present in String AA after
position 9. Its position is 59

I know BB is included in the first 9 positions of AA,
but it is included in the rest of the string?
(no case sensitive) BB is present in String AA after
position 9.
Its position is 19

Is CC included in string AA after position 9?(no case
sensitive)
BB is not a substring of AA after position 9










   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML