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
  1. Home
  2. General Programming
  3. C#
  4. split issue

split issue

Scheduled Pinned Locked Moved C#
helpregextutorial
5 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    varsh12
    wrote on last edited by
    #1

    static string DecodeUnicode(string s)
    {
    StringBuilder sb=new StringBuilder();
    while (s.Length!=0)
    {
    sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber));
    s=s.Substring(6);
    }
    return sb.ToString();
    }

    string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
    s=DecodeUnicode(s);

    I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.

    e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";

    error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx

    L I 2 Replies Last reply
    0
    • V varsh12

      static string DecodeUnicode(string s)
      {
      StringBuilder sb=new StringBuilder();
      while (s.Length!=0)
      {
      sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber));
      s=s.Substring(6);
      }
      return sb.ToString();
      }

      string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
      s=DecodeUnicode(s);

      I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.

      e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";

      error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      if your input string does not consist only of \\uddd sequences (where each d is a digit), then you need to search for such substrings and replace them one by one by the character they represent. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • V varsh12

        static string DecodeUnicode(string s)
        {
        StringBuilder sb=new StringBuilder();
        while (s.Length!=0)
        {
        sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber));
        s=s.Substring(6);
        }
        return sb.ToString();
        }

        string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
        s=DecodeUnicode(s);

        I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.

        e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";

        error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        Well, first... If you type this:

        string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";

        Then the compiler is already converting the double-backslashes to single-backslashes... But assuming you actually have the doubles in the string... Try just using string.Replace()...

        s = s.Replace(@"\\",@"\")

        The @ sign before the first quote tells C# to ignore the escape characters (Including things like newlines and tabs)... You could also write s.Replace("\\\\","\\");

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        L 1 Reply Last reply
        0
        • I Ian Shlasko

          Well, first... If you type this:

          string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";

          Then the compiler is already converting the double-backslashes to single-backslashes... But assuming you actually have the doubles in the string... Try just using string.Replace()...

          s = s.Replace(@"\\",@"\")

          The @ sign before the first quote tells C# to ignore the escape characters (Including things like newlines and tabs)... You could also write s.Replace("\\\\","\\");

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi Ian, this is yet another episode in a long story, I still don't know what his application is about, but I think of it as some sort of compiler, where the input actually does contain double slashed codes, and needs to treat the escapes. In the current post, the double backslashes are present inside some string which should not have been displayed as a string literal; proof of that is it all worked well until he appended "abc". I'm afraid he is still not really grasping what the escape mechanism does and doesn't do. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          I 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi Ian, this is yet another episode in a long story, I still don't know what his application is about, but I think of it as some sort of compiler, where the input actually does contain double slashed codes, and needs to treat the escapes. In the current post, the double backslashes are present inside some string which should not have been displayed as a string literal; proof of that is it all worked well until he appended "abc". I'm afraid he is still not really grasping what the escape mechanism does and doesn't do. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            I Offline
            I Offline
            Ian Shlasko
            wrote on last edited by
            #5

            Well, Replace is still easier :)

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            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