Pages

Showing posts with label split string. Show all posts
Showing posts with label split string. Show all posts

Thursday, September 26, 2013

Split string, ignoring Case,ignoring blank values and Select Distinct split values



String str = "ankit,Ankit,ankit, , ,aNkit,rahul";

here, we have to split above string  by ','


var split_values = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct(StringComparer.CurrentCultureIgnoreCase); 



You will get :

ankit
rahul



Tuesday, September 17, 2013

Function to convert the text into the link - C#



 string str="dsdhd sdsdhsd http://www.google.com dssdd sdd http://yahoo.co.in";

 string output=formattedData(str);              // call function



 public string formattedData(string str)
    {
        try
        {
            string full = string.Empty;
            string temp = string.Empty;
            string[] arra = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string o in arra)
            {
                temp = o;

                if (o.ToString().ToLower().Contains("http://") == true)
                {
                    temp = "<a target=\"_blank\" href=" + "\"" + o.ToString() + "\"" + ">" + o.ToString() + "</a>";
                }
                full = full + " " + temp;
            }
            return full.ToString().Trim();
        }
        catch (Exception ex)
        {
            return " ";
        }
    }




OUTPUT:

dsdhd sdsdhsd http://www.google.com dssdd sdd http://yahoo.co.in