Link to home
Start Free TrialLog in
Avatar of Sha1395
Sha1395

asked on

Split the string based on Decimal point

Hi,

I have ths code,i want to split the string based on decimal point

Eg: Jack.Smith

i want to split the sting and get only smith

my code

String = " Jack.Smith"

 if (username.Contains("."))
           
         {            
           // username = username.Replace(".", " ");
              string updateuser=username.Substring(0,username.IndexOf("."));
               Console.WriteLine(updateuser);
          }
ASKER CERTIFIED SOLUTION
Avatar of crysallus
crysallus
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please try the following:

string username = " Jack.Smith";

if (username.Contains("."))
{            
	string[] names = username.Split('.');
	
	Console.WriteLine(names[1].Trim());
}

Open in new window


I hope this helps.
Hi

Please try the following code.
string str = "Jack.Smith";
            if (str.Contains('.'))
            {
                // When we do split on the string, it will internally store as a string arry. to print all the values
               // i am doing the foreach loop
                foreach (var item in str.Split('.'))
                {
                    Console.WriteLine(item.ToString());
                }
            }

Open in new window

Let me know your feed back..

Thanks
Sri Narayana Rao.D