how to split line exist in a file using a particular string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aphoorva a
    New Member
    • Oct 2011
    • 2

    how to split line exist in a file using a particular string

    how to split line exist in a file using (particular)str ing(ex., and ,or,etc., )
    need of c# code for the above problem statement

    mine is only working only for seperators

    thanks
    aphoorva
  • irina45
    New Member
    • Oct 2011
    • 4

    #2
    use nested loops.
    like:
    split by first separator
    for each received substring
    split by second separator
    for each received substring
    and so on

    it seems that it may be calling of recursion function

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      The String.Split method actually takes strings as well. If your separator is a full string, try this...

      Code:
      string sourceString = "line1-split-line2";
      string[] results = sourceString.Split(new string[] { "-split-" }, StringSplitOptions.RemoveEmptyEntries);
      
      foreach (string line in results)
        Console.WriteLine(line);
      Output:
      line1
      line2

      Comment

      Working...