Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one text box in which value is like Code/10023. Actually What i want is that how many the letters there after the slash(/), i want to show that in messagebox..
Result should be like 10023. I dont know how to do this i was trying using substring but i am not able to achieve this..
Posted
Comments
BiteForce 9-Jul-13 8:09am    
You could do it like this:
-Textbox.Text.Substring(Textbox.Text.IndexOf("/") + 1).Length;

Substring[^] is Ok. Combine with IndexOf[^] to get the index where to start the substring.
 
Share this answer
 
 
Share this answer
 
Comments
wots up frnds 9-Jul-13 8:16am    
its just concept actually we need the solution
Try this:
C#
string s =textbox.text;
string[] words = s.Split('/');

MessageBox.Show(words[1]);


hope it helps :)
 
Share this answer
 
v2
try this
VB
string str = TextBox1.Text;
str = str.Substring(str.LastIndexOf("/") + 1, str.Length - Convert.ToInt32(str.LastIndexOf("/") + 1));
MessageBox.Show(str);
 
Share this answer
 
v2
try this

XML
string str = "Code/10023";
        string[] StrIn = str.Split('/');
        Response.Write("First String: "+StrIn[0].ToString() + "</br>");
        Response.Write("Second String: "+StrIn[1].ToString()  + "</br>");
        Response.Write("No of Letters: "+StrIn[1].Length);
 
Share this answer
 
This is the solution to your problem

protected void Button1_Click(object sender, EventArgs e)
{
string val = TextBox1.Text.Trim();
string strVal = val.Substring(val.LastIndexOf("/"));
string finalVal=strVal.Remove(0, 1);
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('" + finalVal + "');", true);
}
 
Share this answer
 

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