|
-
May 9th, 2005, 09:22 PM
#1
Thread Starter
Member
[Resolved]what if the textBox is empty? - Truncating white spaces...
Not anymore.
Iam trying to truncate the leading and trailing white spaces in a text box.How do I do it.
I am trying this piece of code,
string myStr = textBox1.Text;
for (int i=0; i<myStr.Length; i++)
{
if (myStr[i]='(')
{
myStr[0]=myStr[i];
}
}
textBox1.Text=myStr;
In this piece of code,
My text starts with ( and ends with ), so Iam checking if the first character is a ( and trying to reset the index of the array to the current position.
But I get the following errors saying
->Cannot implicitly convert type 'char' to 'bool'
->Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
please help
Last edited by cybertechno; May 10th, 2005 at 01:20 AM.
Reason: Resolved
-
May 9th, 2005, 09:39 PM
#2
Member
Re: Truncating white spaces from text in a textBox
Use Trim();
string myStr = textBox1.Text.Trim();
Good luck;
-
May 9th, 2005, 11:10 PM
#3
Thread Starter
Member
Re: Truncating white spaces from text in a textBox
Thanks a million!
Should have known it would be this simple with .NET.
-
May 10th, 2005, 12:05 AM
#4
Thread Starter
Member
What happens if textBox1.text is empty?
what would happen if the textBox1.text is empty?
-
May 10th, 2005, 12:23 AM
#5
Member
Re: what if the textBox is empty? - Truncating white spaces...
Nothing...are you wanting to test to make sure it's not empty?
-
May 10th, 2005, 01:11 AM
#6
Thread Starter
Member
Re: what if the textBox is empty? - Truncating white spaces...
"Nothing...are you wanting to test to make sure it's not empty?"
I just want to know if I leave the Textbox empty and after
String Str=textBox1.text.Trim();
what would be the value of Str ?
-
May 10th, 2005, 01:17 AM
#7
Member
Re: what if the textBox is empty? - Truncating white spaces...
It won't have a value, it'll be nothing. Same as if you didin't have the Trim().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|