473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help formating string

Opa
I have a string with n number of characters. I'm trying to create another string which is exactly 12 characters having leadings zeros and the input string at the end

ex: string1 = "7344", I want to format string1 such that it results another string with string1 at the end and leading zeros in front of it like: "0000000073 44

so I try string2=String. Format(??????,s tring1

does anyone know the correct formatting expression

Thank
Nov 16 '05 #1
4 1831
I think you'll need to cast it to an int first so

int x = string.Parse(st ring1);//Must be able to be parsed or exception will
be thrown.

MessageBox.Show (x.ToString("00 0000000000"));

This will cause it to be 12 long with the difference between the lengths
shown in 0's
"Opa" <an*******@disc ussions.microso ft.com> wrote in message
news:32******** *************** ***********@mic rosoft.com...
I have a string with n number of characters. I'm trying to create another string which is exactly 12 characters having leadings zeros and the input
string at the end.
ex: string1 = "7344", I want to format string1 such that it results another string with string1 at the end and leading zeros in front of it
like: "0000000073 44"
so I try string2=String. Format(??????,s tring1)

does anyone know the correct formatting expression?

Thanks

Nov 16 '05 #2
MS
I suggest you should rather us
string2=string1 .PadLeft(12,'0' );
Nov 16 '05 #3
Opa
Thanks guys

this works.
Nov 16 '05 #4
While using PadLeft, as others have suggested, is a more elegant solution,
you COULD use string.Format as follows:

string s1 = "7344";
string s2 = string.Format( "{0:00000000000 0}", int.Parse( s1 ));

The result would be the same...

Barry

"Opa" <an*******@disc ussions.microso ft.com> wrote in message
news:32******** *************** ***********@mic rosoft.com...
I have a string with n number of characters. I'm trying to create another string which is exactly 12 characters having leadings zeros and the input
string at the end.
ex: string1 = "7344", I want to format string1 such that it results another string with string1 at the end and leading zeros in front of it
like: "0000000073 44"
so I try string2=String. Format(??????,s tring1)

does anyone know the correct formatting expression?

Thanks

Nov 16 '05 #5

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

Similar topics

0
1456
by: sj | last post by:
Im trying to read sample values from aiff files but can not seem to get the unpacking right. Ths following code reads n frames from a sample file and prints the amplitudes to the terminal. In the call to struct.unpack 'h' is the only formating string I can use without getting the message "struct.error: unpack str size does not match format" However the output is wrong. The test file contains a single cycle sine wave which is positive...
13
1594
by: yy0127 | last post by:
I don't know why i entered the below code and it will miss some records. Anyone can help me??? users = {} users1 = {} while 1: user, serviceType, msgType, inOut, date, time, numBytes =
17
2349
by: Phil McKraken | last post by:
I am having a problem putting together a shopping cart with the below script. Everything displays fine, adds totals fine, and works perfect EXCEPT if you choose the 9.95 item #5 BY ITSELF the total displayed is $9.94 ! If you add ANYTHING else the total is correct, 9.95 plus whatever you add. That is the only price in these samples that is doing that. All the others display properly. If you change the 9.95 to ANY other number it displays...
8
4995
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to string and print it. but i want to use the String.Format() method if possible to do it.
2
1751
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need a function to take two arguments:(a double number which may or may not be an integer, and an integer which will be the number of digits to store after the decimal place) it needs to turn this into a string which is always 10 characters long. if the...
1
1613
by: nico | last post by:
Hi, I need to do a lot of string formating, and I have strings and/or unicode strings and when I do the following: "%s %s" % (u'Salut', 'H\xe4llo'), I get an exception : UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128) How can I insure I don't get an exception? Thanks, Nicolas
9
6284
nine72
by: nine72 | last post by:
Ok, so I have figured out how to parse an custom returned XML doc (actually a string that I made into a doc for testing). At this point I am attempting to integrate my parse routine into my main code and I am having an issue getting it to mesh, and am looking for a little help in how to 1) combine the two and 2) how to catch the incoming xml string. FYI the string is sent to me as a return message to an xml message that I send first....
9
2306
by: =?Utf-8?B?TmVpbEdvdHQ=?= | last post by:
I am trying to format a decimal number such as 0.0567 but forgot how to do formatting in C#. I tried the old C format escape sequence "\8.3f" the old C style but does not work. example: dMyNumber.tostring("\8.3f"); Can some one refresh how to do this? Thanks
1
6759
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1041) at java.awt.Container.add(Container.java:365) at orderingsystem.OrderingSystem.<init>(OrderingSystem.java:261) at...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.