Re: C# String Trim() Error!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Dat,


This code is working fine on my end and I am getting the expected
output.Could u please more elobrate ur problem.

Thanks,
Hitesh


Dat K. AU DUONG wrote:
Hi,

C# Annoying string function or Am I doing Something wrong?

In VB6/VB.NET I can code like:
value = value.trim()

and it just work!


But in c#, I event put in the additional check I still get the error.
if (value.Length > 0 && value != string.Empty){
value = value.trim();
}

The error message:
startIndex cannot be larger than length of string.
Parameter name: startIndex at
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32
length, Boolean fAlwaysCopy) ...

Please Help!
Thanks.
Regards Dat.

.