-6

I have a record

"Information Technology (IT) > IT Project Management / Team Lead;
Information Technology (IT) > IT Management;
Information Technology (IT) > Network & System"

I am trying to get the data like:

IT Project Management / Team Lead
IT Management
Network & System

Can anybody give me a suggestion to get the solution please. Thanks

only
  • 1
  • 1
  • 1
    What did you tried, so far? – Jatin Parmar Oct 19 '15 at 17:06
  • 1
    How is that data stored? Is it just a string? – Tim Freese Oct 19 '15 at 17:07
  • thanks for quick reply.As I mentioned above that I have a string value "Information Technology (IT) > IT Project Management / Team Lead; Information Technology (IT) > IT Management; Information Technology (IT) > Network & System" . I am trying to split the value in a string list like "IT Project Management / Team Lead" "IT Management" "Network & System" – only Oct 19 '15 at 17:10
  • string a = "Information Technology (IT) > IT Project Management / Team Lead; Information Technology (IT) > IT Management; Information Technology (IT) > Network & System"; string[] splitted = a.Split(';'); foreach (string item in splitted) { Console.WriteLine(item.Substring(item.IndexOf(">")+1)); } – Naveen Bathina Oct 19 '15 at 17:21
  • thanks @NaveenBathina. I have also resolved and my answer is string val = "Information Technology (IT) > IT Project Management / Team Lead; Information Technology (IT) > IT Management; Information Technology (IT) > Network & System"; string[] newval21 = val.Split(';'); List words11 = new List(); foreach (string s in newval21) { var ss = s.Split('>'); words11.Add(ss[1]); Console.WriteLine(ss[1]); } – only Oct 20 '15 at 10:49

1 Answers1

0

It appears that you can split the string based on the ';' character.

https://msdn.microsoft.com/en-us/library/ms228388.aspx

    char[] delimiterChars = { ';' };        
    string text = @"Information Technology (IT) > IT Project Management / Team Lead; Information Technology (IT) > IT Management; Information Technology (IT) > Network & System";
    System.Console.WriteLine("Original text: '{0}'", text);

    string[] words = text.Split(delimiterChars);
    System.Console.WriteLine("{0} words in text:", words.Length);

    foreach (string s in words)
    {
        System.Console.WriteLine(s);
    }
KristianJ
  • 1
  • 4
  • i need the result like: "IT Project Management / Team Lead", "IT Management" ,"Network & System" in list. But your solution gives the result like: "Information Technology (IT) > IT Project Management / Team Lead",..where as I am trying to split "Information Technology (IT) >" – only Oct 19 '15 at 17:14
  • You should be able to remove the portion that you don't want to display after splitting (in the foreach loop). s.Remove("Information Technology (IT) > "); – KristianJ Oct 19 '15 at 17:18
  • @Trogdor.exactly but how to achieve this. I am struggling for 2 days. – only Oct 19 '15 at 17:22
  • You further need to split `s` to another string array using `>` as delimiter to get the second part – haraman Oct 19 '15 at 17:22
  • @only Use Trogdor's method above and further split `s` inside foreach loop using `string[] finalwords = s.Split(">"c);` and then access second part by refering `finalwords[1].Trim` – haraman Oct 19 '15 at 17:46
  • Sorry, I should have said s = s.Remove("Information Technology (IT) > "); – KristianJ Oct 19 '15 at 17:48
  • thanks @Trogdor your answer make me the right way. I have resolved my problem and the answer is string val = "Information Technology (IT) > IT Project Management / Team Lead; Information Technology (IT) > IT Management; Information Technology (IT) > Network & System"; string[] newval21 = val.Split(';'); List words11 = new List(); foreach (string s in newval21) { var ss = s.Split('>'); words11.Add(ss[1]); Console.WriteLine(ss[1]); } – only Oct 20 '15 at 10:52
  • You're welcome. Please up-vote my answer if you can. Thanks. – KristianJ Oct 20 '15 at 14:33
  • Somehow I've been given a temporary answer ban... I'm new so I'd appreciate the benefit of the doubt from the moderators / voters. I guess that I'll wait out the ban before contributing again?? – KristianJ Oct 20 '15 at 14:59
  • Hello @Dave-Zych or other moderators. Is there a way to unblock my ability to contribute to answers? I don't see a way to "correct" previous answers. Thanks. – KristianJ Oct 22 '15 at 01:21
  • @varocarbas can you please tell me why my answer ability is block with no way to "correct" the previous answers? thanks. – KristianJ Oct 23 '15 at 20:08
  • Sorry, I meant blocked. – KristianJ Oct 23 '15 at 22:11