Solved

How to mask/limit string output in C#?

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Count with a subquery showing details 10 42
Batch file or script with password 22 41
Sql Server group by 10 26
Call Controller Action Method from ASPX 2 13
In this article I will describe the Copy Database Wizard 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.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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