|
-
Sep 26th, 2007, 12:10 AM
#1
Thread Starter
New Member
Simple String problem
Hi,
I am a bit in asp c#. I am reading a file
Patient Name: GEORGE ABRAMS Sex:Male
Patient Name: John B RAMS Sex:Male
Patient Name: Sandy SA ABRAMS Sex:Male
Patient Name: GEORGE ABRAMS Sex:Male
Patient Name: Smith ABRAMS Sex:Male
I want the the following output:-
GEORGE ABRAMS male
John B RAMS Male
Sandy SA ABRAMS Male
GEORGE ABRAMS male
...
..
I have a string sflie = "Patient Name: GEORGE ABRAMS Sex:Male"
whats the best an easy way.
Also in the new file there should not be any repetations like line 1 and 4 are the same. The output file should Not have same entry.
Any help would be great
Thanks
-
Sep 26th, 2007, 07:42 AM
#2
Re: Simple String problem
Take the postion of : and Sex and Extract the inner text using the substring method. Then use ArrayList Collection object to store this values.Before adding these values to the array list,check whether the value exist in the array list using .Contains method of the ArrayList.If u want to some coding please do comeback
Please mark you thread resolved using the Thread Tools as shown
-
Sep 26th, 2007, 10:39 AM
#3
Member
Re: Simple String problem
Dear aspnetprog,
As i think you split the string using String.Split function according to ":" then validate the string. for example,
Code:
string sfile = "Patient Name: GEORGE ABRAMS Sex:Male";
string[] splirt = sfile.Split(char.Parse(":"));
foreach(string s in splirt)
{
if (!s.Contains("Patient Name"))
{
if (s.Contains("Sex"))
{
string ss = s.Substring(0, s.IndexOf("Sex"));
Console.Write(ss);
}
else
{
Console.Write(s);
}
}
}
Thanks..
-
Sep 26th, 2007, 09:43 PM
#4
Thread Starter
New Member
Re: Simple String problem
thanks Sekarm. that code works fine
But now in new file there should not be any repetitions like line 1 and 4 are the same. The output file should Not have same entry.
GEORGE ABRAMS male
John B RAMS Male
Sandy SA ABRAMS Male
GEORGE ABRAMS male
I dont want repetitions...any help
-
Sep 27th, 2007, 03:48 AM
#5
Member
Re: Simple String problem
Dear aspnetprog,
As Danasegarane told you have add string file in Arraylist. Use ArrayList.Contains function you may check the current file is added or not. then you may not get repitation.
Thanks...
-
Sep 28th, 2007, 09:50 PM
#6
Thread Starter
New Member
Re: Simple String problem
Thanks a lot. I will try thr arraylist.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|