Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken String.this[] #343

Closed
ishvedov opened this issue Jun 13, 2018 · 3 comments · Fixed by nanoframework/nf-interpreter#742
Closed

Broken String.this[] #343

ishvedov opened this issue Jun 13, 2018 · 3 comments · Fixed by nanoframework/nf-interpreter#742

Comments

@ishvedov
Copy link

Details about Problem

nanoFramework area: interpreter

Worked before? Yes, old firmware's. At least ESP32 668.

Detailed repro steps so we can see the same problem

Console.WriteLine("a\nb"[1].ToString());

return 'b', must '\'.

@ghost
Copy link

ghost commented Jun 13, 2018

Can't check myself but what about adding a '@' in front of the string : Console.WriteLine(@"a\nb"[1].ToString());
This would not solve the issue but could be a temporary workaround ?

Also, how does this behave ? Console.WriteLine("a\\nb"[1].ToString());
(again, I can't test myself, I am away from home this week)

@ishvedov
Copy link
Author

@MikroBusNet no workaround possible, because on this functionality based PR for CoreLib.

@josesimoes
Copy link
Member

josesimoes commented Jun 13, 2018

This is deeper than some wrong indexing of the string chars.
Seems to be related with wrong handling/conversion of the string on the CLR_RT_UnicodeHelper.

Test code:

        public static void Main()
        {
            // string with new line char, output one char at a time
            string s = "a\nb7#zx03";

            Console.WriteLine("char output for '" + @"a\nb7#zx03" + "' iterating trough string chars");

            for(int i = 0; i < s.Length; i++)
            {
                Console.WriteLine(" " + s[i] + " (" + ((byte)s[i]) + ")");
            }

            Console.WriteLine("");

            // string with new line char, output from ToCharArray()
            var sAsArray = s.ToCharArray();

            Console.WriteLine("");
            Console.WriteLine("char output for '" + @"a\nb7#zx03" + "' as a char array");
            Console.WriteLine("length of string 's' is " + s.Length);
            Console.WriteLine("length of char array is " + sAsArray.Length);
            Console.WriteLine("");

            foreach (char c in sAsArray)
            {
                Console.WriteLine(" " + c +" (" + ((byte)c) + ")");
            }

            // string withOUT new line char, output from ToCharArray()
            s = "1w+F5?=zQ";

            sAsArray = s.ToCharArray();

            Console.WriteLine("");
            Console.WriteLine("char output for '" + s + "' as a char array");
            Console.WriteLine("length of string 's' is " + s.Length);
            Console.WriteLine("length of char array is " + sAsArray.Length);
            Console.WriteLine("");

            foreach (char c in sAsArray)
            {
                Console.WriteLine(" " + c + " (" + ((byte)c) + ")");
            }

            Thread.Sleep(Timeout.Infinite);
        }

Output from the above in nF app:

char output for 'a\nb7#zx03' iterating trough string chars
 a (97)
 b (98)
 7 (55)
 # (35)
 z (122)
 x (120)
 0 (48)
 3 (51)
  (64)


char output for 'a\nb7#zx03' as a char array
length of string 's' is 9
length of char array is 9

 a (97)
 b (98)
 7 (55)
 # (35)
 z (122)
 x (120)
 0 (48)
 3 (51)
  (0)

char output for '1w+F5?=zQ' as a char array
length of string 's' is 9
length of char array is 9

 1 (49)
 w (119)
 + (43)
 F (70)
 5 (53)
 ? (63)
 = (61)
 z (122)
 Q (81)

Output from .NET 4.6 console app:

char output for 'a\nb7#zx03' iterating trough string chars
 a (97)

 (10)
 b (98)
 7 (55)
 # (35)
 z (122)
 x (120)
 0 (48)
 3 (51)


char output for 'a\nb7#zx03' as a char array
length of string 's' is 9
length of char array is 9

 a (97)

 (10)
 b (98)
 7 (55)
 # (35)
 z (122)
 x (120)
 0 (48)
 3 (51)

char output for '1w+F5?=zQ' as a char array
length of string 's' is 9
length of char array is 9

 1 (49)
 w (119)
 + (43)
 F (70)
 5 (53)
 ? (63)
 = (61)
 z (122)
 Q (81)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants