Hello,
//I am using devExpress' combo box in my project
//i passed its in the string list as
string[] list=cmb.editvalue.tostring();
the out put is like that ('A A',' BBB',' C CC' etc)
Now i want to remove only the leading space in each element of the array i try this ;
plz guide me if there any function to remove the spaces in array
i use
list.replace("",empty.string)
but it removed the spaces between elements as well
how can i get the output ('A A','BBB','C CC')
Thanx in advance
REMOVE leading Spaces in String Array
Page 1 of 14 Replies - 5867 Views - Last Post: 07 May 2010 - 10:09 PM
Replies To: REMOVE leading Spaces in String Array
#2
Re: REMOVE leading Spaces in String Array
Posted 07 May 2010 - 11:56 AM
Use the Trim method:
Alternatively, you could use TrimStart.
EDIT: Needed to fix the code.
// Loop through each string.
for (int i = 0; i < list.Length; i++)
{
// Remove any leading/trailing whitespace characters.
list[i] = list[i].Trim();
}
Alternatively, you could use TrimStart.
EDIT: Needed to fix the code.
This post has been edited by lesPaul456: 07 May 2010 - 12:02 PM
#3
Re: REMOVE leading Spaces in String Array
Posted 07 May 2010 - 11:59 AM
You could use string.TrimStart. Here's an example (just for simplicity sake I just load them into a ListView
Hope that helps
private void TrimStartExample()
{
string[] sample = new string[] { "A A", " BBB", " C CC" };
foreach (string s in sample)
{
ListView1.Items.Add(s.TrimStart(new char[] { ' ' }));
}
}
Hope that helps
#4
Re: REMOVE leading Spaces in String Array
Posted 07 May 2010 - 04:29 PM
Quote
ListView1.Items.Add(s.TrimStart(new char[] { ' ' }));
Maybe you guys won't be in agreement with me, but since this is a parameter and we know that the idea behind trimming for the most part is removing whitespace, I think it's better to omit the char array.
ListView1.Items.Add(s.TrimStart());
I just think it looks cleaner and since it's not necessary, why add it?
EDIT: when I said "but since this is a parameter", I mean that it's a params parameter, not just the fact that it's a method parameter. Sorry for confusion.
This post has been edited by MentalFloss: 07 May 2010 - 04:29 PM
#5
Re: REMOVE leading Spaces in String Array
Posted 07 May 2010 - 10:09 PM
TAanks a lot
Its solve my problem
Its solve my problem
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|