neo-devpack-dotnet
neo-devpack-dotnet copied to clipboard
Operations regarding characters are not working as intended
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#.

It seems that it works as a byte array inside the VM
Yes @shargon , that is the issue, however, it is possible for the compiler to fix this, by checking the byte value
@lock9 how the compiler will distinguish between a string and a byte array without the type?
@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