Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Easy question. syntax.

Posted on 2008-06-19
8
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21827226
use SubString:

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

Expert Comment

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

Expert Comment

by:Rahul Goel ITIL
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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