Solved

How to mask/limit string output in C#?

Posted on 2011-03-14
3
792 Views
Last Modified: 2013-12-17

hello,

how can I set a length of string in an output?

I'm having a statement as sb.Append(String.Format("\"{0}\"", order.FullName)).Append(",");

However, I need to limit FullName field to 25 character and not more.

Thanks.
0
Comment
Question by:akohan
[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
3 Comments
 
LVL 10

Accepted Solution

by:
Nash2334 earned 125 total points
ID: 35131381
string fullName = string.Empty;

if (order.FullName.Length > 24)
  fullName = order.FullName.Substring(0, 25);
else
  fullName = order.FullName;
0
 

Author Closing Comment

by:akohan
ID: 35131533
Thanks
0
 
LVL 15

Expert Comment

by:colly92002
ID: 35131545
string myLongString = "Big text long long big long text more than 25 characters BIIIIIIIGGGGGGGG";

string myFixedString = myLongString.Remove(25);
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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