mathieu_cupryk
asked on
Easy question. syntax.
I need to do a trim of 80.
How can I do this it is not working on this.
gradeName = cellGradeValue.Value2.ToSt ring().Tri m(80);
Error 1 The best overloaded method match for 'string.Trim(params char[])' has some invalid arguments C:\SvnWork\InitialPriceRep orting\Dot Net\Initia lPriceRepo rting\Form 1.cs 1027 37 InitialPriceReporting
Error 2 Argument '1': cannot convert from 'int' to 'char[]' C:\SvnWork\InitialPriceRep orting\Dot Net\Initia lPriceRepo rting\Form 1.cs 1027 75 InitialPriceReporting
How can I do this it is not working on this.
gradeName = cellGradeValue.Value2.ToSt
Error 1 The best overloaded method match for 'string.Trim(params char[])' has some invalid arguments C:\SvnWork\InitialPriceRep
Error 2 Argument '1': cannot convert from 'int' to 'char[]' C:\SvnWork\InitialPriceRep
ASKER
'NO.2 CANADA WESTERN AMBER DURUM (15.1) '
trim the rest of the spaces.
I don't think trim 80 will work.
trim the rest of the spaces.
I don't think trim 80 will work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here we go again. I replaced the literal number 80 with the parameter length. This should solve your problem.
/// <summary>
/// Removes the trailing characters to the number
/// specified by <paramref name="length"/>.
/// </summary>
public string TruncateString(string s, int length)
{
int removeStartIndex = s.Length - length;
if(removeStartIndex <= 0)
return String.Empty;
return s.Remove(removeStartIndex);
}
use SubString:
gradeName = cellGradeValue.Value2.ToSt ring().Sub string(0, 80);
gradeName = cellGradeValue.Value2.ToSt
Are the single quotes part of the string?...
This will work for you
cellGradeValue.Value2.ToString().Substring(0,80).Trim()
I'm having another after misunderstanding the question the first time. This should trim all spaces at the end of a string.
String s = "NO.2 CANADA WESTERN AMBER DURUM (15.1) ";
s.TrimEnd(new char[] { ' ' });
ASKER