New course! Every coder should learn Generative AI!
Try a free lesson0
c#
How to trim space between letter int b=0; string a =null; a=textbox1.Text; b=a.length. richtextbox1= b.tostring(); How to know when i write bo ok (length =5) bo ok (length=4)i want to convert length like this
8 Answers
+ 4
That will completely remove the spaces. So, taking the length of that is what you want.
So,
String a = "An ex for you";
// a.length() is : 13
a = a.Replace(" ", "");
// a is now: "Anexforyou"
a.length();
// so this will be: 10
Or, if you didn't actually want to change a.
In your code you could write this:
int b = (a.Replace(" ", "")).length;
That will take the length of the string disregarding spaces.
+ 1
Could try using Replace(String, String)
Example/
a = (textbox1.text).Replace(" ", "");
This will remove the spaces in the string.
(Could also use String.Empty instead of "").
+ 1
How about length ?
How many length that it show ?
+ 1
(a.Replace(" ", ""))
This is going to return you a mew string with all spaces replaces with empty characters.
(a.Replace(" ",")).length;
Then taking the length of that, is taking the length of the string with no spaces.
0
int b = (a.Replace(" ", "")).length;
if I use like this what dose it show me sir?
0
@lee ratana please do notice.
Your question has to go in the field question, the field description is the body of the question and the field tags are the keywords of the question.
0
@sneeze I'm not sure , so I decide to ask again , thank you for your advice 😊
0
@lee ratana. You have good questions so it is a shame all your questions have the title "c#".