JG Vimalan's Blog

It is all about coding!

Remove empty strings, spaces and \r\n in string array

In this code sample, I am going to show how to remove empty string, newline characters in string array.

I have a string array as shown below and used StringSplitOptions.RemoveEmptyEntries to remove any empty elements in the array.

string [] clinics = ConfigurationManager.AppSettings[“MyClinicList”].Split(newchar[] {‘,’}, StringSplitOptions.RemoveEmptyEntries);

Now, I found that, the clinics array elements are having white spaces \r\n due to newline. So, used Array.ForEach and Trim method as shown below,

Array.ForEach<string>(clinics, val => clinics[Array.IndexOf<string>(clinics, val)] = val.Trim());

This gave the expected result.

May 18, 2012 Posted by | C#.NET | Leave a comment

Either DataSourceSettingName or ConnectionString and TableName must be specified and cannot be empty.

I got this error when I compiled  my Coded UI test developed in Visual Studio 2010.

This occured after I added data source to my unit test method.  The test method with data source is as shown below,

[DataSource(“Microsoft.VisualStudio.TestTools.DataSource.XML”, “|DataDirectory|\\Source.xml”, “”, DataAccessMethod.Sequential), DeploymentItem(“TestProject1\\Source.xml”), TestMethod]
        public void CodedUITestMethod1()
        {

To fix this issue, provide valid table name as shown below,

[DataSource(“Microsoft.VisualStudio.TestTools.DataSource.XML”, “|DataDirectory|\\Source.xml”, “EmployeeName“, DataAccessMethod.Sequential), DeploymentItem(“TestProject1\\Source.xml”), TestMethod]
        public void CodedUITestMethod1()
        {

This will fix the issue.

May 17, 2012 Posted by | C#.NET, Coded UI Test | 2 Comments