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

string.IndexOf("string") not working in Raspberry Pi project #33997

Closed
digital-spinner opened this issue Mar 23, 2020 · 4 comments
Closed

string.IndexOf("string") not working in Raspberry Pi project #33997

digital-spinner opened this issue Mar 23, 2020 · 4 comments
Labels
area-System.Globalization question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@digital-spinner
Copy link

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;

File content:

57 01 4b 46 7f ff 0c 10 38 : crc=38 YES
57 01 4b 46 7f ff 0c 10 38 t=21437

w1_slave.txt

The same file content (whole file) copied and run in Windows yield with proper parsed value.

Am I missing something here? What is even funnier the same code before worked but can't recall exact framework versions etc..

@GrabYourPitchforks GrabYourPitchforks transferred this issue from dotnet/core Mar 24, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Runtime untriaged New issue has not been triaged by the area owner labels Mar 24, 2020
@GrabYourPitchforks
Copy link
Member

@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?

@tarekgh
Copy link
Member

tarekgh commented Mar 24, 2020

@GrabYourPitchforks

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.

@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:

    string sensorStatus = System.IO.File.ReadAllText(path);
    foreach (char c in sensorStatus)
    {
        Console.WriteLine($"{c} ... {(int)c:x}");
    }

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.

@tarekgh tarekgh added question Answer questions and provide assistance, not an issue with source code or documentation. and removed untriaged New issue has not been triaged by the area owner labels Mar 24, 2020
@tarekgh tarekgh added this to the 5.0 milestone Mar 24, 2020
@GrabYourPitchforks
Copy link
Member

Yes, string.IndexOf, not string.Contains. My error. :)

@digital-spinner
Copy link
Author

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!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Globalization question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants