c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

25th Jul 2017, 4:02 AM
lee ratana
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.
25th Jul 2017, 4:35 AM
Rrestoring faith
Rrestoring faith - avatar
+ 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 "").
25th Jul 2017, 4:15 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
How about length ? How many length that it show ?
25th Jul 2017, 4:31 AM
lee ratana
+ 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.
25th Jul 2017, 3:44 PM
Rrestoring faith
Rrestoring faith - avatar
0
int b = (a.Replace(" ", "")).length; if I use like this what dose it show me sir?
25th Jul 2017, 5:38 AM
lee ratana
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.
25th Jul 2017, 10:41 AM
sneeze
sneeze - avatar
0
@sneeze I'm not sure , so I decide to ask again , thank you for your advice 😊
25th Jul 2017, 10:46 AM
lee ratana
0
@lee ratana. You have good questions so it is a shame all your questions have the title "c#".
25th Jul 2017, 1:24 PM
sneeze
sneeze - avatar