Solved

How to mask/limit string output in C#?

Posted on 2011-03-14
3
786 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

707 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

14 Experts available now in Live!

Get 1:1 Help Now