neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

Operations regarding characters are not working as intended

Open luc10921 opened this issue 4 years ago • 4 comments

Using operations relating to characters is not working as intended, e.g.,:

	public static void Main()
	{
		string Str = "ΔδΣΦφ";
		int LengthOfStr = Str.Length;
		string SubStr1 = Str.Substring(1, 4);
		string SubStr2 = Str.Substring(2, 3);
		string SubStr3 = Str.Substring(3, 2);
		Console.WriteLine(Str);
		Console.WriteLine(LengthOfStr);
		Console.WriteLine(SubStr1);
		Console.WriteLine(SubStr2);
		Console.WriteLine(SubStr3);
	}

Running the code above in C# results in:

ΔδΣΦφ
5
δΣΦφ
ΣΦφ
Φφ

However, when running the same code in Neo, it ends up considering the number of bytes instead of the number of characters, so, every time a char that is not present in the ASCII table is used, the behaviour will diverge from C#. image

luc10921 avatar Oct 05 '21 20:10 luc10921

It seems that it works as a byte array inside the VM

shargon avatar Oct 06 '21 08:10 shargon

Yes @shargon , that is the issue, however, it is possible for the compiler to fix this, by checking the byte value

lock9 avatar Oct 06 '21 16:10 lock9

@lock9 how the compiler will distinguish between a string and a byte array without the type?

shargon avatar Oct 07 '21 08:10 shargon

@shargon The compiler is the only one who knows that this is an string, but not the VM. What we probably need, is to add a 'stringSize', in addition to the 'size' opcode - and make the compiler use the correct one. There should be a need of adding other opcodes to be able to work with UTF-8 strings properly

lock9 avatar Oct 07 '21 16:10 lock9