Results 1 to 6 of 6

Thread: Simple String problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    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

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  3. #3
    Member
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    33

    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..

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    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

  5. #5
    Member
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    33

    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...

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    8

    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
  •  



Click Here to Expand Forum to Full Width