Hello,
When I tried to parse numerical value from TMPro input text field and I received an error below. I tried to lock the input field as integer, disabled rich text, but it didn’t help. Unity 2022.3.10f1, TMPro 3.0.6.
int value = int.Parse( textfield.text );
Error message:
FormatException: Input string was not in a correct format.
System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) (at <787acc3c9a4c471ba7d971300105af24>:0)
System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) (at <787acc3c9a4c471ba7d971300105af24>:0)
System.Int32.Parse (System.String s) (at <787acc3c9a4c471ba7d971300105af24>:0)
After investigation I found out that output text contains ascii character 8203 which is “Zero Width Space” attached at the end of output string, which is invisible in console. So I fixed it by trimming last character this way:
string str = textfield.text[ ..^1 ];
int value = int.Parse( str );
I don’t know why is character like this contained there, but it is not so friendly output of input field which is locked to integer.