I think you don't want to remove anything, you need to determine two separate numbers from the list box item. The solution is simple:
http://msdn.microsoft.com/en-us/library/ms131448%28v=vs.110%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/b3h1hf19%28v=vs.110%29.aspx[
^]:
string[] numbers = myItemText.Split('-', System.StringSplitOptions.RemoveEmptyEntries);
int left = int.Parse(numbers[0]);
int right = int.Parse(numbers[1]);
The only problem is: this is a bad dumb solution!
The real solution is to store proper data in your list items, not strings. (This is a curse of beginners these days: trying to work with strings representing data instead of data itself.) The type if the list item can be any object. Create a type which holds the data you need, which you could safely use later. For example:
struct MyListItem {
internal MyListItem(int left, int right) { this.Left = left; this.Right = right; }
internal int Left { get; private set; }
internal int Right { get; private set; }
public override string ToString() { return string.Format("{0}-{1}", Left, Right); }
}
Why
System.Object.ToString()
is overridden here? Because this is what is shown in an item on screen. This way, you use original data, with no string parsing. Strings should be used only for output, presentation.
Now when you need this data, you case the item to the type
MyListItem
and directly access
MyListItem.Left, MyListItem.Right
.
—SA