473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

producing strings of various formats

I have a string in following format ,
XXdd XXX

Where X exists b/w. A - z
d exists b/w. 0 - 9

I want to format them in the following manner,
xxdd xxx
xx dd xxx
xxd dxxx
xx ddxxx
xxddx xx
x xddxxx
x xdd xxx
xxd d xxx
xxdd xx x
xxdd x xx
xxx dd xx x
xxx ddx x x

is there any simple and easy way through which i can convert a single string
into multiple strings of my desired format.

regards,
Beenish Khan

Nov 17 '05 #1
1 1394
Is there some speedy .NET Framework method you can call? No.

In my opinion, the best way to code this so that it can be easily
understood and maintained is as follows.

I suppose that each part of your original string has some meaning. That
is, they're not just seven random characters tossed together. It looks
to me as though you have groups of characters that mean things. So, for
example, perhaps the two x's before the d's represent some code for
something, the digits represent something else, etc. I would pick the
original string apart and put the resulting bits into strings that
describe what they mean.

To take another example, imagine that you know that the string you're
receiving contains the location of a seat in a stadium. It consists of
a letter indicating the level (lower or upper), a code indicating the
section, a row number, and a seat code. You could then pick the string
apart like this:

string levelCode = seatingLocation.Substring(0,1);
string sectionCode = seatingLocation.Substring(1, 2);
string rowNumber = seatingLocation.Substring(3, 3);
string seatNumber = seatingLocation.Substring(6, 2);

Now you can format the string however you like:

string printingSeatingLocation = String.Format("{0}{1}/{2}/{3}",
levelCode, sectionCode, rowNumber, seatNumber);

etc.

Is this the fastest way to do it, CPU-wise? Probably not. However,
three years from now you'll be able to come back, read the code again,
and understand exactly what you did and why.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fernando Rodriguez | last post by:
Hi, How can I extract all the strings in an exe with python? O:-)
11
by: Amy G | last post by:
I have seen something about this beofore on this forum, but my google search didn't come up with the answer I am looking for. I have a list of tuples. Each tuple is in the following format: ...
15
by: Richard Hollenbeck | last post by:
For example, one college course has only 24 students in it, but the following code says there are zero As, 20 Bs, 16 Cs, 4 Ds, and 8 Fs. When it prints it then says 0 As, 40 Bs, 32 Cs, 8 Ds, and...
0
by: Robert Misiak | last post by:
Hi all- I'm trying to add Windows 98/ME support to an app that previously only supported Windows 2000+. My test box is a running 98 SE. I have a number of localized forms (translated for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.