473,804 Members | 4,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pad Middle of string with zeros

Ben
Hi

I have a string which is at least 4 characters but can be more which I need
to pad, with zeros, to a full length of 15 after the 3rd charactor.

Eg '1234' to '12300000000000 4'

How can I do this?

Also how can I truncate this back to 4 or however many charactors (e.g.
123000000000400 = 123400)

Any help will be much appreciated

Thanks
B
Nov 21 '05
10 2638
Ben
Thanks for the posts

Sorry for the delayed response

Thanks
B
"Diana Mueller" <diana@nospam > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

"Ben" <Be*@NoSpam.com > schrieb im Newsbeitrag
news:up******** ******@TK2MSFTN GP12.phx.gbl...
Hi

I have a string which is at least 4 characters but can be more which I

need
to pad, with zeros, to a full length of 15 after the 3rd charactor.

Eg '1234' to '12300000000000 4'

How can I do this?


1. split the string into "123" and "4" (check out String.Substrin g())
2. pad the second string (check out String.PadLeft( ))
3. concatenate the two string (check out String.Concat() )

Also how can I truncate this back to 4 or however many charactors (e.g.
123000000000400 = 123400)


remove the 4th character from your string (check out String.Remove() )
while
it equals "0" (while loop with String.Equals() ).

If you want to improve your knowledge on algorithms, i suggest the books
by
Robert Sedgewick.

Nov 21 '05 #11

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

Similar topics

6
6655
by: Paul E Collins | last post by:
Given a string variable (form input), how can I determine whether it represents a valid integer? is_numeric is true for floats as well as integers, and is_int always fails on a string. P.
4
4260
by: __PPS__ | last post by:
Hello, I have a function that does some decoding (same as urldecode in php) and it returns std::string std::string urldecode(const char* in, std::size_t length); so, this function parses input and constructes output char by char. I tried to use all sorts of direct access to the buffer of std::string to be returned but it's always slow. It appered that if I dynamically allocate memory fill it with output, then create std::string from this...
17
14366
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart, int longueur) { char *resultat = " "; char *temporaire = " "; int nbr;
10
43476
by: Yang Lee | last post by:
hi is this correct char teststr="\0"; or is there another method to initialise; thanks lee
4
1832
by: Opa | last post by:
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: "000000007344 so I try string2=String.Format(??????,string1 does anyone know the correct formatting expression Thank
1
312
by: Ben | last post by:
Hi I have a string which is at least 4 characters but can be more which I need to pad, with zeros, to a full length of 15 after the 3rd charactor. Eg '1234' to '123000000000004' How can I do this? Also how can I truncate this back to 4 or however many charactors (e.g.
6
7616
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
6
19204
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function doesn't create leading zeros. The Format function (format(value,"X") doesn't create leading zeros. I believe there should be a simple way that doesn't involving measuring and padding the string.
11
45635
by: ram23 | last post by:
Hi friends, i need help .. i am getting String value and i need to add leading zeros.. total length of Target string is 13char eg: suppose if i get 12 as values.. it needs to convert into 0000000000012
2
1229
by: =?Utf-8?B?SExvbmc=?= | last post by:
Could someone give a hand on how to handle this issue: I need to find a way of removing zeros from files names. The zeros in the names are used to sort the file name, e.g. MAK0080.pci, MAK-0080.pci. What I need to do is to remove the zeros, so the file names become MAK80.pci o MAK-80.pci. I have done something in Visual Basic using the Mid() function and going thru the string removing the zeros. Is there a better way of doing this,...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
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
10319
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
10076
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
9144
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...
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.