In C #, how to determine if a string has a carriage return using the String.Contains function? Return ascii for carriage - 13.
String.Contains
Chr(13) is how carriage returns are presented in Visual Basic. How is carriage return in C # represented using the ascii character rather than "\r" ?
Chr(13)
"\r"
if (word.Contains(Chr(13)) { . . . }
Since you are declaring that you do not want to use \r , then you can apply an integer to char :
\r
char
if (word.Contains((char)13)) { ... }
if (word.Contains(Environment.NewLine)) { }
You can enter a char value using single quotes
var s = "hello\r"; if (s.Contains('\r')) { }
If you find it easier to read, you can cast 13 to char
13
var s = "hello\r"; if (s.Contains((char)13)) { }
This is valid in all versions of .NET:
if (word.Contains("\r")) { ... }
This is true only from .NET 3.5:
if (word.Contains('\r')) { ... }
Convert.Char(byte asciiValue) creates a char from any integer; So
Convert.Char(byte asciiValue)
if (word.Contains(Convert.Char(13))
must do the job.
s.Contains('\x0D');
characters are single quotes;
What is wrong with using \ r?
I'm sure you can do this with a regex, but if you're stupid like me, this extension method is a good way:
public static bool HasLineBreaks(this string expression) { return expression.Split(new[] { "\r\n", "\r", "\n" },StringSplitOptions.None).Length > 1; }
Source: https://habr.com/ru/post/901324/More articles:Is it possible to display a js file using Rails and minimize output? - ruby-on-railsAndroid: how to update Android app using inapp binary? - androidreading a word file in C # - c #https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/901322/remove-a-specific-changeset-from-git-repository-altogether&usg=ALkJrhgmtbddulLXPJortAEP2lU_WJErVQHow to make recursive loops in scala - scalaHow to use Android PowerProfile private API? - androidhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/901326/quantiles-of-sums-using-copula-distributions-too-slow&usg=ALkJrhi7Tk99zHrlCmmAtmYyY3EtEb2ZkQHow to check if the type std :: vector :: iterator is at compile time? - c ++Throw checked exceptions from anonymous inner classes - javacannot statically refer to non-static fields - javaAll Articles