I am trying to perform a string replace, but it results in:"No overload for method Replace accepts 2 arguments."
What I need to do: fetch string(usernames) separated by "." and store only the 1st half.
input can be eu.rails.io or in.rails.io, or fr.rails.io
desired result eu, in, fr
geo = geo.Replace(".rails.io", "");
(declared this variable geo earlier)
//results in error— "No overload for the method Replace takes 2 arguments"
(edited with 'geo'var)
CodePudding user response:
Edit: If the Replace
Method has an error, the variable geo
might not be a string.
Multiple possibilities. You could replace the part ".rails.io"
as you suggested:
string geo = "eu.rails.io";
geo = geo.Replace(".rails.io", string.Empty);
You could also split the string at the point, and only use the first part (you need to be sure, that the string you want to keep doesn't contain a dot):
string geo = "eu.rails.io";
geo = geo.Split('.')[0];
CodePudding user response:
username = username.Remove(username.IndexOf("."));