Solved

Easy question. syntax.

Posted on 2008-06-19
8
343 Views
Last Modified: 2013-12-16
I need to do a trim of 80.
How can I do this it is not working on this.
gradeName = cellGradeValue.Value2.ToString().Trim(80);


Error      1      The best overloaded method match for 'string.Trim(params char[])' has some invalid arguments      C:\SvnWork\InitialPriceReporting\DotNet\InitialPriceReporting\Form1.cs      1027      37      InitialPriceReporting
Error      2      Argument '1': cannot convert from 'int' to 'char[]'      C:\SvnWork\InitialPriceReporting\DotNet\InitialPriceReporting\Form1.cs      1027      75      InitialPriceReporting
0
Comment
Question by:mathieu_cupryk
8 Comments
 

Author Comment

by:mathieu_cupryk
ID: 21827116
I should trim the after spaces?
0
 

Author Comment

by:mathieu_cupryk
ID: 21827124
'NO.2 CANADA WESTERN AMBER DURUM (15.1)                                                   '

trim the rest of the spaces.

I don't think trim 80 will work.
0
 
LVL 18

Accepted Solution

by:
Richard Lee earned 500 total points
ID: 21827215
Here is a function that will do what you need:

/// <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 - 80;

      if(removeStartIndex <= 0)
            return String.Empty;

      return s.Remove(removeStartIndex);
}
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 21827224
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);

}

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21827226
use SubString:

gradeName = cellGradeValue.Value2.ToString().Substring(0, 80);
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21827432
Are the single quotes part of the string?...
0
 
LVL 9

Expert Comment

by:Rahul Goel
ID: 21828608
This will work for you

cellGradeValue.Value2.ToString().Substring(0,80).Trim()

Open in new window

0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 21829210
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[] { ' ' });

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now