You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
string.IndexOf("string") not working in Raspberry Pi project #33997
I have recently upgraded .NET Core 3.1 SDK to version v3.1.200 with Visual Studio Community 2019 and I'm building and application for Raspberry Pi where one part of it reads the content on specific file from filesystem and parses it (very simple).
Some days ago (don't remember previous core version) but it was working correctly. Now suddently stopped. The problem is with searching of a specific substring position in the file using string.IndexOf method. It always gets me return value of -1 for whatever string I search for, even with only char inside. But when I search for last char of '=' it gives me proper index result. (But I want to search for "t=" substring here anyway)..
string sensorStatus = System.IO.File.ReadAllText(path);
int index = sensorStatus.IndexOf("t=") + 2;
string temperatureString = sensorStatus.Substring(index, 5);
double result = Convert.ToDouble(temperatureString) / 1000;
@tarekgh The overload string.Contains(string) uses CultureInfo.CurrentCulture for comparison. Did we change how ICU works when running on RPi systems in 3.1?
The overload string.Contains(string) uses CultureInfo.CurrentCulture for comparison. Did we change how ICU works when running on RPi systems in 3.1?
did you mean string.IndexOf as the issue not reported with the Contains method? We didn't change anything in 3.1 specifics to RPi nor any other system. We have a global change that avoiding using POSIX/C locales and use Invariant culture instead.
It will be hard to tell what could be the problem, the only thing I can think of could be the codepage used for reading the file. could you please try after reading the whole text, print every single character:
Also, could you please get the value of the environment variable LANG from the system? and let's know if the environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT is defined in the system.
OK, thank you and I'm very sorry for disturbing you all.. Everything works as intended except my SDCARD which was used in my Raspberry Pi. I have finally discovered this issue when my app started failing during web server initialization when tried to ask about System Culture etc. After I replaced that everything started to work again.
Activity
GrabYourPitchforks commentedon Mar 24, 2020
@tarekgh The overload
string.Contains(string)usesCultureInfo.CurrentCulturefor comparison. Did we change how ICU works when running on RPi systems in 3.1?tarekgh commentedon Mar 24, 2020
@GrabYourPitchforks
did you mean
string.IndexOfas the issue not reported with theContainsmethod? We didn't change anything in 3.1 specifics to RPi nor any other system. We have a global change that avoiding using POSIX/C locales and use Invariant culture instead.@digital-spinner
It will be hard to tell what could be the problem, the only thing I can think of could be the codepage used for reading the file. could you please try after reading the whole text, print every single character:
Also, could you please get the value of the environment variable
LANGfrom the system? and let's know if the environment variableDOTNET_SYSTEM_GLOBALIZATION_INVARIANTis defined in the system.GrabYourPitchforks commentedon Mar 24, 2020
Yes,
string.IndexOf, notstring.Contains. My error. :)digital-spinner commentedon Mar 24, 2020
OK, thank you and I'm very sorry for disturbing you all.. Everything works as intended except my SDCARD which was used in my Raspberry Pi. I have finally discovered this issue when my app started failing during web server initialization when tried to ask about System Culture etc. After I replaced that everything started to work again.
Again sorry and thank you for your support!