Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

i have string like 122012 and i want to split this string into string 1=12 and string 2=2012.

how can i do this.
Posted
Comments
So, what have you tried?

Take a look at String.Substring and/or String.Split method.
 
Share this answer
 
v2
string Value="122012";
string s1=Value.SubString(0,2);
string s2=Value.SubString(2,4);

this is just coded for test to get two strings for the requirement
 
Share this answer
 
Try using Substring instance in C#.

C#
string str = "122014";
string s1 = str.Substring(0, 2);
string s2 = str.Substring(2, 4);
 
Share this answer
 
string yrs="122012";

StringBuilder firstPart=new StringBuilder();
StringBuilder secondPart=new StringBuilder();

for(int i=0;i<yrs.length;i++)>
{
if (i < 2)
{
firstPart.Append(yrs[i]);
}
else
{
secondPart.Append(yrs[i]);
}
}
 
Share this answer
 
v2
Learn to do it yourself: substring[^]
 
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