Avatar of banu111
banu111
 asked on

How to extract some part of the string

Hi friends I have a full computer name MyComputer.Mytest.local stored in the database
i want just the domain like Mytest.local .
How can extract it from the string like

string name=MyComputer.Mytest.local;
to Mytest.local;
or is there pattern to recognize domain name from full computer name
Application ServersC#ASP.NET

Avatar of undefined
Last Comment
banu111

8/22/2022 - Mon
banu111

ASKER
Do they have Regex pattern for this
ASKER CERTIFIED SOLUTION
Minh Võ Công

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dmitry G

One way to handle this is to split the total name into substrings using "." as a delimiter:

            string name = "MyComputer.Mytest.local";
            string[] subnames = name.Split(new char[] { '.' });
            foreach (string s in subnames)
            {
                Console.Out.WriteLine(s);
            }

Open in new window


Output:

MyComputer
Mytest
local


You may use array elements to build any string or use in any other way you want.
Anuradha Goli

string name = "MyComputer.Mytest.local";
int index = name.IndexOf('.');
name = name.Substring(index + 1, name.Length - index - 1);
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
banu111

ASKER
if  name=MyComputer.Mytest.local  or name=Mytest.local. If I want to test the string if it contains more than one (.) then  only extract the string. I got the answer for extracting the string but how to check the (.) condition