0

ok this is my question. i have this url

http://mycountry.county.india.com

and i want this in return

MYCOUNTRY.country.india.com

I have written a using SPLIT in C#. But that is bad though it does the job done. Anyone having a better solution in C#?

ANOTHER EXAMPLE

For this

http://my5-pc.in.aaa.com

i want this in return

MY5-PC.in.aaa.com

7
  • regex101.com/r/oE6jJ1/27 you can use relace.Replace by $1.upper or something` Commented Nov 26, 2014 at 9:05
  • 1
    Can you give more than one example? Presumably you have more than one URL you need to deal with and it's difficult for us to understand what the actual requirement is when we only have one example to generalize from. Commented Nov 26, 2014 at 9:06
  • Do you just want to remove http:// ? or www. or any similar scenario ? is mycountry always the first word or is this a variable? Commented Nov 26, 2014 at 9:09
  • @Damien_The_Unbeliever check for another example in my edited question. Commented Nov 26, 2014 at 9:11
  • @MXD remove http:// and the put everything in caps till the first . Occurs . N.B. There wont be like www after http in my case and mycountry is always first word and it is not a variable Commented Nov 26, 2014 at 9:13

1 Answer 1

1

If you just want to remove the http:// and capitalize the first word I would refrain from using Regex as this is slow in general. Http:// is always 7 characters long and could easily be removed using a simple string.remove or Substring

str.Substring(7, str.Length-7)
str.Remove(0, 7);

And as far as it seems you want the word before the first '.' to be capitalized. For that you could use something like

int index = str.IndexOf('.');
if(index > 0) {
    string firstWord = str.Substring(0, index);
    str = firstWord.ToUpper + str.Substring(index, str.Length);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.