Trim String Array
-
I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array
string[] apiresult = new string[25]; char[] splitter = { ';' }; apiresult = result.Split(splitter);
My question is, how do I trim the string array so it just containssuccess 1 Bob etc...
instead ofresult=success userid=1 firstname=Bob etc...
result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;
-
I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array
string[] apiresult = new string[25]; char[] splitter = { ';' }; apiresult = result.Split(splitter);
My question is, how do I trim the string array so it just containssuccess 1 Bob etc...
instead ofresult=success userid=1 firstname=Bob etc...
result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;
This should work: string[] finalResult = new string[apiresult.Length]; for (int i = 0; i < apiresult.Length; i++) { finalResult[i] = apiresult[i].Substring(apiresult[i].IndexOf('=')+1); } Don't be afraid of loops. :) Cheers
rotter
modified on Saturday, August 16, 2008 11:41 PM
-
I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array
string[] apiresult = new string[25]; char[] splitter = { ';' }; apiresult = result.Split(splitter);
My question is, how do I trim the string array so it just containssuccess 1 Bob etc...
instead ofresult=success userid=1 firstname=Bob etc...
result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;
Hi! Try using this string [] tokens = myString.split (new char[] {';' , '='}); foreach (string s in tokens) { //do something to s; } DONT use a fixed array string !!!!
-
I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array
string[] apiresult = new string[25]; char[] splitter = { ';' }; apiresult = result.Split(splitter);
My question is, how do I trim the string array so it just containssuccess 1 Bob etc...
instead ofresult=success userid=1 firstname=Bob etc...
result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;
It didn't get lost, you just didn't look for it http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2677761[^]