Solved

C# array manipulation

Posted on 2011-03-14
2
435 Views
Last Modified: 2012-05-11
I need a string with concatenated "status code" and "reason code".  Both should be concatenated as shown following. If Status code and reason codes are less than 2 characters, they should be left alligned and a space should be left... If they are more than 2 characters, they should be truncated to 2 characters.

Example:
If account has following status reason codes:
Status Code--Reason Code
AA            -- Y
BU             -- CD
B               -- 9

The result string is “AAY BUCDB 9 “
0
Comment
Question by:vivekj2004
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35129311
Something like this?
string statusCode = "AA";
string reasonCode = "Y";

string result = string.Concat(statusCode.PadRight(2, ' ').Substring(0, 2), reasonCode.PadRight(2, ' ').Substring(0, 2));

Open in new window

0
 

Author Comment

by:vivekj2004
ID: 35132529
Thanks Kaufmed. 100% solution would be to enclose this in a foreach loop to collect all the status codes.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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