1

I am upgrading one of the net framework project to net5, observed a change in behavior of a same line of code in net framework vs net5. For example if I have a text wit EOT, net5 doesn't give the index but the same works in net framework project.

string sampleString = "hello" + "\u0004" + "test";
string delimiter = "\u0004";
var test = sampleString.IndexOf(delimiter);
\\Net framework gives a index **5**
\\Net core gives a index **0** for the code

Any reason for this change in behavior?

Prasad
  • 93
  • 8
  • https://learn.microsoft.com/en-us/dotnet/standard/base-types/string-comparison-net-5-plus – Steve Dec 27 '21 at 13:39
  • 6
    Does this answer your question? [C# "anyString".Contains('\0', StringComparison.InvariantCulture) returns true in .NET5 but false in older versions](https://stackoverflow.com/questions/65574888/c-sharp-anystring-contains-0-stringcomparison-invariantculture-returns-tr) – Mark Benningfield Dec 27 '21 at 13:40

1 Answers1

2

try this

string delimiter = "\u0004";
string sampleString = "hello" + delimiter + "test";

var uniCodeValue = char.Parse(delimiter);//  '\u0004' unicode values
var test = sampleString.IndexOf(uniCodeValue); //5
test = sampleString.IndexOf("test"); //6
Serge
  • 40,935
  • 4
  • 18
  • 45