How to do it:
string list = "one; two; three;four"; List<string> values = new List<string>(); string[] tempValues = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries); foreach (string tempValue in tempValues) { values.Add(tempValue.Trim()); }
on one line, something like this:
List<string> values = extras.Split(';').ToList().ForEach( x => x.Trim()); //error
You need to use Selectit if you want to perform the conversion for each instance in IEnumerable<T>.
Select
IEnumerable<T>
List<string> values = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
Ease of use of the LINQ selection method:
var values = "one; two; three;four".Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim());
List<string> values = new List<string>(list.Split(new char[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries));
No explicit Trim(). Also not LINQ. Add \t, \r, \nin the char [], if there are other spaces.
Trim()
\t
\r
\n
Source: https://habr.com/ru/post/1727791/More articles:Rails: link to partial? - ruby ββ| fooobar.comCannot delete french letters in string returned by python ball - pythonHow to create a shortcut in SendToFolder for all users with WiX? - windows-installerReading PDF Data in SharePoint Lists - pdfΠΠ΅ΡΠ΅Π΄Π°ΡΡ ΠΏΠΎ ΡΠ΅ΠΊΡΡΡ Textbox.Text - c#HttpOnly cookie in SharePoint interrupts browser workflow creation - workflowHow does BackupAgent work? - androidObjective C - initialization of inherited variables of a subclass object - objectJSF ReRender support using selectBooleanCheckbox - jsfSeries caching in MySQL? - mysqlAll Articles