Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. small problem

small problem

Scheduled Pinned Locked Moved C#
helpquestiondata-structuresjson
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    snouto
    wrote on last edited by
    #1

    hi all. I just need to ask one question ! how can split the incoming string into string array by finite small string i know that split method for normal string can split the string into string array but with specific character not exceed one character like the following -------------------------------------- using System; namespace snouto { class stringargs { static void Main(string[] args) { string string1 = "hi#thatisme#yeah"; //here if i splitted the current string //using split method it will split it by //character # like char[] splitters = {'#'}; string[] separated = string1.split(splitters); } In the above code i split my string into string array using # character format but if i want to split my string by using another string like "snouto" in tha above string string string1 = "hisnoutoThatismesnoutoYeah"; how can i split the above string using snouto which repeated inside the string Please help Miss With The Best And Die Like The Rest

    S L 2 Replies Last reply
    0
    • S snouto

      hi all. I just need to ask one question ! how can split the incoming string into string array by finite small string i know that split method for normal string can split the string into string array but with specific character not exceed one character like the following -------------------------------------- using System; namespace snouto { class stringargs { static void Main(string[] args) { string string1 = "hi#thatisme#yeah"; //here if i splitted the current string //using split method it will split it by //character # like char[] splitters = {'#'}; string[] separated = string1.split(splitters); } In the above code i split my string into string array using # character format but if i want to split my string by using another string like "snouto" in tha above string string string1 = "hisnoutoThatismesnoutoYeah"; how can i split the above string using snouto which repeated inside the string Please help Miss With The Best And Die Like The Rest

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      AFAIK, there is no predefined method for what you want to do. You have to explicitly loop through the characters in the string and split them. Off the top of my head,

      string[] Split(string text, string separator)
      {
      ArrayList splitStrings = new ArrayList();

      int index = -1;
      int prevIndex = index;
      while ((index = text.IndexOf(separator, prevIndex)) != -1) // while we have separators
      {
      // Split from previous found position to current position
      splitStrings.Add(text.Substring(prevIndex, index-prevIndex));
      prevIndex = index + separator.Length;
      }
      return (string[]) splitStrings.ToArray(typeof(string));
      }

      Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      • S snouto

        hi all. I just need to ask one question ! how can split the incoming string into string array by finite small string i know that split method for normal string can split the string into string array but with specific character not exceed one character like the following -------------------------------------- using System; namespace snouto { class stringargs { static void Main(string[] args) { string string1 = "hi#thatisme#yeah"; //here if i splitted the current string //using split method it will split it by //character # like char[] splitters = {'#'}; string[] separated = string1.split(splitters); } In the above code i split my string into string array using # character format but if i want to split my string by using another string like "snouto" in tha above string string string1 = "hisnoutoThatismesnoutoYeah"; how can i split the above string using snouto which repeated inside the string Please help Miss With The Best And Die Like The Rest

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        string[] StringSplit(string input, string sep)
        {
        const char S = (char)255;
        return input.Replace(sep, S.ToString()).Split(S);
        }

        xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        I 1 Reply Last reply
        0
        • L leppie

          string[] StringSplit(string input, string sep)
          {
          const char S = (char)255;
          return input.Replace(sep, S.ToString()).Split(S);
          }

          xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

          I Offline
          I Offline
          IamJunk
          wrote on last edited by
          #4

          Instead you can rely on more popular regular expressions. try this... //add this to the using section at the top of the class using System.Text.RegularExpressions; string original = "hisnoutoThatismesnoutoYeah"; Regex reg = new Regex("snouto"); //"snouto" or what ever string[] splitStrings = reg.Split(original); Using Regular Expressions is comparatively faster that any other operations directly on strings Hope this helps!!!


          Regards, Sidhu IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB Dotnet @ Work Where Dotnet works... My Blog

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups