What's wrong with my usage of String.EndsWith? The Next CEO of Stack OverflowWhat's the false operator in C# good for?What's the strangest corner case you've seen in C# or .NET?The located assembly's manifest definition does not match the assembly referenceCase insensitive 'Contains(string)'C# difference between == and Equals()Are string.Equals() and == operator really same?Ajax request returns 200 OK, but an error event is fired instead of successd is less efficient than [0-9]Why not inherit from List<T>?What's with the dollar sign ($“string”)
Grabbing quick drinks
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
Does the Brexit deal have to be agreed by both Houses?
Trouble understanding the speech of overseas colleagues
How easy is it to start Magic from scratch?
Go Pregnant or Go Home
Anatomically Correct Strange Women In Ponds Distributing Swords
Need some help with wall behind rangetop
Why do remote companies require working in the US?
How to start emacs in "nothing" mode (`fundamental-mode`)
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
Is HostGator storing my password in plaintext?
Rotate a column
Anatomically Correct Mesopelagic Aves
How do spells that require an ability check vs. the caster's spell save DC work?
If the heap is initialized for security, then why is the stack uninitialized?
Whats the best way to handle refactoring a big file?
Why do professional authors make "consistency" mistakes? And how to avoid them?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Is it okay to store user locations?
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
How do we know the LHC results are robust?
What's the point of interval inversion?
What's wrong with my usage of String.EndsWith?
The Next CEO of Stack OverflowWhat's the false operator in C# good for?What's the strangest corner case you've seen in C# or .NET?The located assembly's manifest definition does not match the assembly referenceCase insensitive 'Contains(string)'C# difference between == and Equals()Are string.Equals() and == operator really same?Ajax request returns 200 OK, but an error event is fired instead of successd is less efficient than [0-9]Why not inherit from List<T>?What's with the dollar sign ($“string”)
I can't figure out why EndsWith is returning false.
I have the C# code:
string heading = "yakobusho";
bool test = (heading == "yakobusho");
bool back = heading.EndsWith("sho");
bool front = heading.StartsWith("yak");
bool other = "yakobusho".EndsWith("sho");
Debug.WriteLine("heading = " + heading);
Debug.WriteLine("test = " + test.ToString());
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("front = " + front.ToString());
Debug.WriteLine("other = " + other.ToString());
The output is:
heading = yakobusho
test = True
back = False
front = True
other = True
What is going on with EndsWith?
c# asp.net ends-with
add a comment |
I can't figure out why EndsWith is returning false.
I have the C# code:
string heading = "yakobusho";
bool test = (heading == "yakobusho");
bool back = heading.EndsWith("sho");
bool front = heading.StartsWith("yak");
bool other = "yakobusho".EndsWith("sho");
Debug.WriteLine("heading = " + heading);
Debug.WriteLine("test = " + test.ToString());
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("front = " + front.ToString());
Debug.WriteLine("other = " + other.ToString());
The output is:
heading = yakobusho
test = True
back = False
front = True
other = True
What is going on with EndsWith?
c# asp.net ends-with
5
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of"sho"
– Diado
Mar 7 at 14:34
1
Different characters, possibly a hidden character. There's nothing wrong withEndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
1
The"sho"
string in the third line is 4 characters long
– Panagiotis Kanavos
Mar 7 at 14:35
add a comment |
I can't figure out why EndsWith is returning false.
I have the C# code:
string heading = "yakobusho";
bool test = (heading == "yakobusho");
bool back = heading.EndsWith("sho");
bool front = heading.StartsWith("yak");
bool other = "yakobusho".EndsWith("sho");
Debug.WriteLine("heading = " + heading);
Debug.WriteLine("test = " + test.ToString());
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("front = " + front.ToString());
Debug.WriteLine("other = " + other.ToString());
The output is:
heading = yakobusho
test = True
back = False
front = True
other = True
What is going on with EndsWith?
c# asp.net ends-with
I can't figure out why EndsWith is returning false.
I have the C# code:
string heading = "yakobusho";
bool test = (heading == "yakobusho");
bool back = heading.EndsWith("sho");
bool front = heading.StartsWith("yak");
bool other = "yakobusho".EndsWith("sho");
Debug.WriteLine("heading = " + heading);
Debug.WriteLine("test = " + test.ToString());
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("front = " + front.ToString());
Debug.WriteLine("other = " + other.ToString());
The output is:
heading = yakobusho
test = True
back = False
front = True
other = True
What is going on with EndsWith?
c# asp.net ends-with
c# asp.net ends-with
asked Mar 7 at 14:30
jtsoftwarejtsoftware
15712
15712
5
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of"sho"
– Diado
Mar 7 at 14:34
1
Different characters, possibly a hidden character. There's nothing wrong withEndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
1
The"sho"
string in the third line is 4 characters long
– Panagiotis Kanavos
Mar 7 at 14:35
add a comment |
5
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of"sho"
– Diado
Mar 7 at 14:34
1
Different characters, possibly a hidden character. There's nothing wrong withEndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
1
The"sho"
string in the third line is 4 characters long
– Panagiotis Kanavos
Mar 7 at 14:35
5
5
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of
"sho"
– Diado
Mar 7 at 14:34
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of
"sho"
– Diado
Mar 7 at 14:34
1
1
Different characters, possibly a hidden character. There's nothing wrong with
EndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
Different characters, possibly a hidden character. There's nothing wrong with
EndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
1
1
The
"sho"
string in the third line is 4 characters long– Panagiotis Kanavos
Mar 7 at 14:35
The
"sho"
string in the third line is 4 characters long– Panagiotis Kanavos
Mar 7 at 14:35
add a comment |
3 Answers
3
active
oldest
votes
The "sho"
string in the third line starts with a zero length space. "sho".Length
returns 4 while ((int)"sho"[0])
returns 8203, the Unicode value of the zero length space.
You can type it in a string using its hex code, eg :
"x200Bsho"
Annoyingly, that character isn't considered whitespace so it can't be removed with String.Trim()
.
add a comment |
This contains an invisible character before the "sho" string:
bool back = heading.EndsWith("sho");
The corrected line:
bool back = heading.EndsWith("sho");
add a comment |
In your EndsWith
argument there is a special character.
As you can see from this code:
class Program
static void Main(string[] args)
string heading = "yakobusho";
string yourText = "sho";
bool back = heading.EndsWith(yourText);
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("yourText length = " + yourText.Length);
string newText = "sho";
bool backNew = heading.EndsWith(newText);
Debug.WriteLine("backNew = " + backNew.ToString());
Debug.WriteLine("newText length = " + newText.Length);
OUTPUT:
back = False
yourText length = 4
backNew = True
newText length = 3
The length of yourText
is 4 and so there is some hidden character in this string.
Hope this helps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046203%2fwhats-wrong-with-my-usage-of-string-endswith%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The "sho"
string in the third line starts with a zero length space. "sho".Length
returns 4 while ((int)"sho"[0])
returns 8203, the Unicode value of the zero length space.
You can type it in a string using its hex code, eg :
"x200Bsho"
Annoyingly, that character isn't considered whitespace so it can't be removed with String.Trim()
.
add a comment |
The "sho"
string in the third line starts with a zero length space. "sho".Length
returns 4 while ((int)"sho"[0])
returns 8203, the Unicode value of the zero length space.
You can type it in a string using its hex code, eg :
"x200Bsho"
Annoyingly, that character isn't considered whitespace so it can't be removed with String.Trim()
.
add a comment |
The "sho"
string in the third line starts with a zero length space. "sho".Length
returns 4 while ((int)"sho"[0])
returns 8203, the Unicode value of the zero length space.
You can type it in a string using its hex code, eg :
"x200Bsho"
Annoyingly, that character isn't considered whitespace so it can't be removed with String.Trim()
.
The "sho"
string in the third line starts with a zero length space. "sho".Length
returns 4 while ((int)"sho"[0])
returns 8203, the Unicode value of the zero length space.
You can type it in a string using its hex code, eg :
"x200Bsho"
Annoyingly, that character isn't considered whitespace so it can't be removed with String.Trim()
.
answered Mar 7 at 14:42
Panagiotis KanavosPanagiotis Kanavos
56.8k483112
56.8k483112
add a comment |
add a comment |
This contains an invisible character before the "sho" string:
bool back = heading.EndsWith("sho");
The corrected line:
bool back = heading.EndsWith("sho");
add a comment |
This contains an invisible character before the "sho" string:
bool back = heading.EndsWith("sho");
The corrected line:
bool back = heading.EndsWith("sho");
add a comment |
This contains an invisible character before the "sho" string:
bool back = heading.EndsWith("sho");
The corrected line:
bool back = heading.EndsWith("sho");
This contains an invisible character before the "sho" string:
bool back = heading.EndsWith("sho");
The corrected line:
bool back = heading.EndsWith("sho");
answered Mar 7 at 14:35
TorTor
344110
344110
add a comment |
add a comment |
In your EndsWith
argument there is a special character.
As you can see from this code:
class Program
static void Main(string[] args)
string heading = "yakobusho";
string yourText = "sho";
bool back = heading.EndsWith(yourText);
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("yourText length = " + yourText.Length);
string newText = "sho";
bool backNew = heading.EndsWith(newText);
Debug.WriteLine("backNew = " + backNew.ToString());
Debug.WriteLine("newText length = " + newText.Length);
OUTPUT:
back = False
yourText length = 4
backNew = True
newText length = 3
The length of yourText
is 4 and so there is some hidden character in this string.
Hope this helps.
add a comment |
In your EndsWith
argument there is a special character.
As you can see from this code:
class Program
static void Main(string[] args)
string heading = "yakobusho";
string yourText = "sho";
bool back = heading.EndsWith(yourText);
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("yourText length = " + yourText.Length);
string newText = "sho";
bool backNew = heading.EndsWith(newText);
Debug.WriteLine("backNew = " + backNew.ToString());
Debug.WriteLine("newText length = " + newText.Length);
OUTPUT:
back = False
yourText length = 4
backNew = True
newText length = 3
The length of yourText
is 4 and so there is some hidden character in this string.
Hope this helps.
add a comment |
In your EndsWith
argument there is a special character.
As you can see from this code:
class Program
static void Main(string[] args)
string heading = "yakobusho";
string yourText = "sho";
bool back = heading.EndsWith(yourText);
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("yourText length = " + yourText.Length);
string newText = "sho";
bool backNew = heading.EndsWith(newText);
Debug.WriteLine("backNew = " + backNew.ToString());
Debug.WriteLine("newText length = " + newText.Length);
OUTPUT:
back = False
yourText length = 4
backNew = True
newText length = 3
The length of yourText
is 4 and so there is some hidden character in this string.
Hope this helps.
In your EndsWith
argument there is a special character.
As you can see from this code:
class Program
static void Main(string[] args)
string heading = "yakobusho";
string yourText = "sho";
bool back = heading.EndsWith(yourText);
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("yourText length = " + yourText.Length);
string newText = "sho";
bool backNew = heading.EndsWith(newText);
Debug.WriteLine("backNew = " + backNew.ToString());
Debug.WriteLine("newText length = " + newText.Length);
OUTPUT:
back = False
yourText length = 4
backNew = True
newText length = 3
The length of yourText
is 4 and so there is some hidden character in this string.
Hope this helps.
answered Mar 7 at 14:46
JoKeRxbLaCkJoKeRxbLaCk
396217
396217
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046203%2fwhats-wrong-with-my-usage-of-string-endswith%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
Copying this out into dotnetfiddle highlights the fact that there's a hidden character at the beginning of
"sho"
– Diado
Mar 7 at 14:34
1
Different characters, possibly a hidden character. There's nothing wrong with
EndsWith()
– Panagiotis Kanavos
Mar 7 at 14:34
1
The
"sho"
string in the third line is 4 characters long– Panagiotis Kanavos
Mar 7 at 14:35