Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 11, 2012 05:47 AM by Ruchira
Member
285 Points
223 Posts
Nov 08, 2012 08:35 AM|LINK
Hello Every one
I have string which contains persion name and his date of birth e.g "AMIT SINGH 1984-12-11"
now i want to split this string into following menner Name=AMIT SINGH and DOB=1984-12-11
can any one help me?
Contributor
2170 Points
484 Posts
Nov 08, 2012 08:38 AM|LINK
string test = "AMIT SINGH 1984-12-11";
string strName = test.Substring(0,9);
string strDOB = test.Substring(11,10);
Regards,
Charan
3988 Points
760 Posts
Nov 08, 2012 08:39 AM|LINK
u can use String.Substring(start,end index)
Participant
752 Points
147 Posts
Nov 08, 2012 08:44 AM|LINK
Hi, You can split the string with space(' ') as following code : string test = "AMIT SINGH 1984-12-11"; string[] strName = test.Split(' '); string name = strName[0] + " " + strName[1]; string dob = strName[2];
You can split the string with space(' ') as following code :
206 Points
50 Posts
Nov 08, 2012 09:36 AM|LINK
you can do it like this exactly :
if you want to get from a textbox just replace the string full_name to the textbox.text
string full_name,name,DOB,person_name;
string[] member;
full_name = "AMIT SINGH 1984-12-11";
// you can enter any charcters you want to split with the newchar[]{ ' '})
member = full_name.Split(new char[] { ' ' });
name = "NAME = "+member[0].ToString()+" "+member[1].ToString();
DOB = "DOB = "+member[2].ToString();
person_name = name + " and " + DOB;
1265 Points
247 Posts
Nov 08, 2012 09:37 AM|LINK
hi,
If that DOB format is fixed then try the following....
string str="AMIT SINGH 1984-12-11";
string pname=str.Trim().SubString(0,str.Length-10);
int namelen=str.Length-10;
string dob=str.Trim().SubString(namelen-1,10);
Hope Helps U.......
1663 Points
329 Posts
Nov 08, 2012 09:50 AM|LINK
Dear amit You can do one thing if it is possible .
if you create the string with this format AMIT SINGH : 1984-12-11
Then you can easily read both information by the following code.
dim strarr as string() dim name as string dim dob as string strarr="AMIT SINGH : 1984-12-11".split(":") name=strarr(0) dob=strarr(1)
All-Star
42973 Points
7024 Posts
MVP
Nov 11, 2012 05:47 AM|LINK
Hello,
Best way is to use Regular expressions to split it. See the following thread. It will help you to achieve this.
http://stackoverflow.com/questions/3720012/regular-expression-to-split-string-and-number
Please 'Mark as Answer' if this post helps you.
amitk.singh
Member
285 Points
223 Posts
how to get substring
Nov 08, 2012 08:35 AM|LINK
Hello Every one
I have string which contains persion name and his date of birth e.g "AMIT SINGH 1984-12-11"
now i want to split this string into following menner Name=AMIT SINGH and DOB=1984-12-11
can any one help me?
Amit Singh
If answer helps you then please mark it as correct.
chaaraan
Contributor
2170 Points
484 Posts
Re: how to get substring
Nov 08, 2012 08:38 AM|LINK
string test = "AMIT SINGH 1984-12-11";
string strName = test.Substring(0,9);
string strDOB = test.Substring(11,10);
Regards,
Charan
pradeep shar...
Contributor
3988 Points
760 Posts
Re: how to get substring
Nov 08, 2012 08:39 AM|LINK
u can use String.Substring(start,end index)
hiral shah
Participant
752 Points
147 Posts
Re: how to get substring
Nov 08, 2012 08:44 AM|LINK
If Post contain helped you, Please Mark as Answer
tarek yehia
Member
206 Points
50 Posts
Re: how to get substring
Nov 08, 2012 09:36 AM|LINK
you can do it like this exactly :
if you want to get from a textbox just replace the string full_name to the textbox.text
string full_name,name,DOB,person_name;
string[] member;
full_name = "AMIT SINGH 1984-12-11";
// you can enter any charcters you want to split with the newchar[]{ ' '})
member = full_name.Split(new char[] { ' ' });
name = "NAME = "+member[0].ToString()+" "+member[1].ToString();
DOB = "DOB = "+member[2].ToString();
person_name = name + " and " + DOB;
maheswari.bo...
Participant
1265 Points
247 Posts
Re: how to get substring
Nov 08, 2012 09:37 AM|LINK
hi,
If that DOB format is fixed then try the following....
string str="AMIT SINGH 1984-12-11";
string pname=str.Trim().SubString(0,str.Length-10);
int namelen=str.Length-10;
string dob=str.Trim().SubString(namelen-1,10);
Hope Helps U.......
gaurabchatte...
Participant
1663 Points
329 Posts
Re: how to get substring
Nov 08, 2012 09:50 AM|LINK
Dear amit You can do one thing if it is possible .
if you create the string with this format AMIT SINGH : 1984-12-11
Then you can easily read both information by the following code.
dim strarr as string() dim name as string dim dob as string strarr="AMIT SINGH : 1984-12-11".split(":") name=strarr(0) dob=strarr(1)Microsoft Technologies
Ruchira
All-Star
42973 Points
7024 Posts
MVP
Re: how to get substring
Nov 11, 2012 05:47 AM|LINK
Hello,
Best way is to use Regular expressions to split it. See the following thread. It will help you to achieve this.
http://stackoverflow.com/questions/3720012/regular-expression-to-split-string-and-number
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.