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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -