ASP.net
ASP / ASP.Net / Vignette
ASP / ASP.Net / Oracle
Books RSS Feed for ASPMatrix.com Book Reviews
 
 
Partner Sites
www.learnasp.com
 
ASPFriends.com

www.411asp.net

www.wwwcoder.com
   
 
ASP.net > String Class Examples > IndexOf
 
IndexOf Example 2 - IndexOf(String)
This will return the index of the specified string in a string. This is case-sensitive. Will return one of THREE things... the position as a positive Integer, 0 for empty, or a  -1 if not found.
 
String to Parse: "Is Brent is a freaking Redneck!" 
 
Code: IndexOf(String)
 
 
View the code to do it below.
 
'------------------- begin code ----------------------------

<%@ Page Language="VB" %>
<script runat="server">
const strParse as string = "Is Brent is a freaking Redneck!"

sub page_load(S as Object, e as EventArgs)
     parseme.text = strParse
 end sub

sub Control_Click(S as Object, E as EventArgs)

     dim sb as new stringbuilder
     dim retval as Int32

     retval = strParse.IndexOf("Redneck")
     if retval > 0 then
          sb.append("<b>Returned " & retval & ", <font color=""#0099FF"">so Brent IS a </font> <font           color=""#CC0000"">Redneck!!!!!!!!</font></b>")
     else
          sb.append("<b>Returned " & retval & ", <font color=""#0099FF"">so Brent IS Just a </font> <font           color=""#CC0000"">DORK!!</font></b>")
     end if

     results.text=sb.tostring()
end sub
</script>

<html>
...

<form runat="server">
Parse: <I><font color="red">"<asp:literal id="parseme" runat="server" />" </font></I><br />
<asp:Button id="btnSubmit" text="Run Code >>" onclick="Control_Click" runat="server" /><br />
<asp:literal id="results" runat="server" /><br />
</form>

...
</html>

'------------------- end code ----------------------------

 
 
       
      Please report all site problems to: webmaster@aspmatrix.com