© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
102 replies
Sal

✅ What is better, in this case, Replace() or Substring()

In Unity it seems that text input comes with a 'Zero Width Space Character' at the end, and that messes with the following logic since a word with 5 characters has 6 characters and this ZWS character ain't accepted everywhere.

Both of this solutions work fine to remove the character, but I am here asking if there is good reasons to use one or another? or even other way maybe even in unity settings to avoid that behavior.

string zeroWidthSpace = new(new char[] { (char)8203 });
name = name.Replace(zeroWidthSpace, "");
string zeroWidthSpace = new(new char[] { (char)8203 });
name = name.Replace(zeroWidthSpace, "");

or

name = name.Substring(0, name.Length-1);
name = name.Substring(0, name.Length-1);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Is it possible to write better switch/case?
C#CC# / help
3y ago
What better?
C#CC# / help
7mo ago
What is this
C#CC# / help
15mo ago