c# - How to remove Whitespce from stringArray formed based on whitespace -


I have a string that contains values.

  90 524 000 1234567890 2207 1926 00: 34 02:40 s   

Now I have broken the string in the string based on white space. Now I want to create another string array in such a way that all white spaces are removed and only have real values ​​in it.

Also, I want to get the position of the string array element from the original string array, which is created by removing the white space from the new string array based on the selection.

Please enter

you via StringSplitOptions.RemoveEmptyEntries From String.Split .

  var value = input.Split (new [] {''}, StringSplitOptions.RemoveEmptyEntries);   

: Return value does not include array elements that contain an empty string

when the split method is given After coping with the white white spot, it will return an empty string. Using StringSplitOptions.RemoveEmptyEntries will remove the empty string and give you only the value you want.

You can also find LINQ

  var values ​​= input.Split (). Where (x => x! = String.Empty). ToArray ();   

Edit: If I understand you correctly, then you want the position of values ​​of your old array. If so, you can do this by creating a word where the keys are actual values ​​and the values ​​are indexed:

  var oldValues ​​= input.Split (''); Var values ​​= input.Split (). Where (x => x! = String.Empty) .ToArray (); Var index = value. To object (x => gt; x, x = & gt; array index (old value, x));   

Then index ["1234567890"] will give you the status of 1234567890 in the first code.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -