I have a list of records that have addresses that are not separated for a mailing list. I want to split the records by the street addresses and city names.
For the first issue, how can I split the records up by the street type e.g. "St", "Drive", "Dr" "Trail" etc.
The String.Split "eats" the "Ct" in this example.
string source1 = "Cxxx, Kxxx,9999 Valleycrest Ct Allen TX 75002 ,,,,,,,,,";
// string source2= "Cxxx, Mxxx Exxx,9999 Chesterwood Dr Little Elm, TX 75068 ,,,,,,,,,";
string[] stringSeparators = new string[] { "Drive", "St", "Dr", "Trail","Ct" };
string[] result;
// ...
result = source1.Split(stringSeparators, StringSplitOptions.None);
foreach (string s in result)
{
Console.Write("'{0}' ", String.IsNullOrEmpty(s) ? "<>" : s);
}
//Objective
// "Cxxx, Kxxx,9999 Valleycrest Ct, Allen, TX, 75002 ,,,,,,,,,"
Here is a sample of the list.
"Pxxx, Sxxx","9999 Southgate Dr McKinney, TX 75070 ",,,,,,,,,
"Hxxxx, Mxxxx","9999 Glendale Ct Allen, TX 75013 ",,,,,,,,,
"Axxxx, Nxxxxx","99999 Balez Drive Frisco, TX 75035 ",,,,,,,,,
"Sxxx, Dxxxx","999 Pine Trail Allen, TX 75002 ",,,,,,,,,
"Vxxx, Sxxxx","9999 Richmond Ave Dallas, TX 75206 ",,,,,,,,,
My list does not include "St Louis" so that will not be an issue.
To simplify my issue.
If I have the following string:
"Cxxx, Kxxx,9999 Valleycrest Ct Allen TX 75002"
and I want to split on the following string "Ct, Dr, Ave"
I want the following result[]
result[0]="Cxxx, Kxxx,9999 Valleycrest Ct" result[1]=" Allen TX 75002"
Because delimiter strings are not included in the elements of the returned array I want them to not be deleted. Is there another option I am missing?
In other words , don't remove the "Ct" "Dr" or whatever separator I find/use.
Thanks