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

I am having a hard time about this one. I have a string in my textbox (milestone_code) and I want to get that string to add another letters to it and the numbers to it will be added by 5. It should be like this:

BOO-45 -----> BOO-CC-50

Can anyone can help me please! I hope you understand my question :)
Posted

1 solution

C#
string input ="BOO-45";
string[] parts = input.Split('-');
int number =Int32.Parse(parts[1]) +5;
string result = parts[0] + "-CC-" +number.ToString();

refer :
Int32.Parse Method[^]
C# Split[^]
 
Share this answer
 
v2
Comments
DarkDreamer08 21-Jul-14 1:21am    
I copied your codes but there is an error pertaining to the line:
int number = Int32.Parse(parts[1])+5;

The error message is "Index was outside the bounds of array"
DamithSL 21-Jul-14 1:30am    
what is the input?
DarkDreamer08 21-Jul-14 3:24am    
hey, I fix it now. The input is based from a query. But I got a problem with this.

SqlCommand cmd = new SqlCommand("SELECT Milestone_Code FROM tblMilestone WHERE Milestone_Name = '"+DropdownList1.Text+"'");
SqlDataReader dr =cmd.ExecuteReader();

if(dr.HasRows)
{
while(dr.Read)
{
string aa = dr.[0].ToString();
string[] parts = aa.Split('-');
int num = Int32.Parse(parts[1] + 5);
string result = parts[0] + "-CC-" + num.ToString();
TextBox1.Text = result;

}
}
dr.Close();

The problem is that it only display the result for the first item in the dropdownlist. and if I select other Items, the result is the same which should not be. Please help me :))
DarkDreamer08 21-Jul-14 3:25am    
Hey, I already fix it now! Thanks for your help. I will mark it as a solution. I hope you could help me again someday :) GOD BLESS!

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