String.Replace working in VB but not C# -
the following vb code works correctly , not flag errors.
strline = strline.replace(strline.lastindexof(","), "")
however same c# code doesn't:
strline = strline.replace(strline.lastindexof(","), "");
this not compile says
the best overloaded method 'string.replace(string,string)' has invalid arguements.
how come works in vb not in c#? , how fix this?
i thought might similar c# string.replace doesn't work implies that code infact complile.
likewise other string.replace questions: string.replace (or other string modification) not working, appears infact compile, whereas mine not.
lastindexof
returns integer, not string. replace
takes string, string
parameters, you're passing int, string
, hence exception the best overloaded method 'string.replace(string,string)' has invalid arguements.
if you're looking remove ,
use this:
strline = strline.replace(",", "");
based on code, may wanting replace last instance of ,
try if that's want:
stringbuilder sb = new stringbuilder(strline); sb[strline.lastindexof(",")] = ""; strline = sb.tostring();
Comments
Post a Comment