Click here to Skip to main content
15,885,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have a s string :

"
C#
$(document).ready(function(){

$("#btn1").submit(function(e1){
   if(e1.keyCode==13){         
       e1.preventDefault();
   }
});
});
"

i want to find a specific content :

"
C#
$("#btn1").submit(function(e1){
   if(e1.keyCode==13){
       e1.preventDefault();
   }
})
"

Any suggestion.
please help!
Posted
Updated 25-Jun-13 23:51pm
v2
Comments
[no name] 26-Jun-13 5:59am    
http://msdn.microsoft.com/en-us/library/dy85x1sa%28v=vs.100%29.aspx

1 solution

Both JS and C# strings have an IndexOf method. This returns the character position if the string is matched. If it's not matched it returns -1.

If you want to check in javascript its

JavaScript
stringValue.indexOf('MyString');


If you need to check none case sensitive

JavaScript
stringValue.toLowerCase().indexOf('mystring');


If you want to check with c#

C#
stringValue.IndexOf("MyString");


Again, not case sensitive

C#
stringValue.toLower().IndexOf("mystring");
 
Share this answer
 
Comments
rohit24c 26-Jun-13 6:03am    
i want to find the entire piece of string
"{

$("#btn1").submit(function(e1){
if(e1.keyCode==13){
e1.preventDefault();
}
});
});"

from the main string
Stephen Hewison 26-Jun-13 6:07am    
And I've just shown you how to do that.
VICK 26-Jun-13 7:47am    
Dude index off basically provide the exact location(index) of the parameter in the string.. i.e if you have a string like....

rohit_24c and if you wana get index of t than you can use indexof("t") which in result will provide you 5 than by using that index in .substring() method you can get the desired string..

For reference see the links below.

http://www.w3schools.com/jsref/jsref_substring.asp

http://www.w3schools.com/jsref/jsref_indexof.asp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900