473,609 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hex formatting in a string?

Hey folks, how can I format a hex string to display as such:

instead of:

10
130
I want the leading values for a full 16 bit address as in:

0010
0130

etc.

Convert.ToStrin g(16, 16) just gives me "10", when I really want "0010".
Id like to use a formatter if there is one for this, otherwise i have
to get into string manipulation, which Id rather avoid.

Dec 23 '06 #1
2 1450
Hi,
you can do the following:

string x = 16.ToString("X4 ");

which will produce "0010"

Mark
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"xlar54" wrote:
Hey folks, how can I format a hex string to display as such:

instead of:

10
130
I want the leading values for a full 16 bit address as in:

0010
0130

etc.

Convert.ToStrin g(16, 16) just gives me "10", when I really want "0010".
Id like to use a formatter if there is one for this, otherwise i have
to get into string manipulation, which Id rather avoid.

Dec 23 '06 #2
If you just have a string to begi with and not an integer, you can use:

string x = "101".PadLeft(4 , '0');

Mark
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"Mark R. Dawson" wrote:
Hi,
you can do the following:

string x = 16.ToString("X4 ");

which will produce "0010"

Mark
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"xlar54" wrote:
Hey folks, how can I format a hex string to display as such:

instead of:

10
130
I want the leading values for a full 16 bit address as in:

0010
0130

etc.

Convert.ToStrin g(16, 16) just gives me "10", when I really want "0010".
Id like to use a formatter if there is one for this, otherwise i have
to get into string manipulation, which Id rather avoid.
Dec 23 '06 #3

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

Similar topics

5
3010
by: Thomas Philips | last post by:
Consider the following simple dictionary e={1:'one', 2: 'two'} e >>>'one' However, If I attempt to print e using a formatted string print " %(1)s" %e, I get a KeyError: '1'
11
1637
by: Steve Holden | last post by:
I was messing about with formatting and realized that the right kind of object could quite easily tell me exactly what accesses are made to the mapping in a string % mapping operation. This is a fairly well-known technique, modified to tell me what keys would need to be present in any mapping used with the format. class Everything: def __init__(self, format="%s", discover=False): self.names = {} self.values =
7
398
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some other country. When I retrieve the phone numbers, I need to display them as (###) ###-#### x 99999 if it is a Canadian number or (###) ###-#### Ext. 99999 if it is US phone number. Potentially I'd have other countries added as well which might have...
2
6315
by: Ken Wilson | last post by:
I am writing and .xml file and am not getting the formatting I would like. The portion of the code that is giving me problems is as follows; XmlTextWriter tw = new XmlTextWriter(filename); tw.Formatting = Formatting.Indented; tw.WriteStartDocument(); tw.WriteStartElement("MyRoot"); tw.WriteStartElement("MyString);
4
3228
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
7
3101
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
8
1770
by: gopal | last post by:
Hi I am trying to write to log file but the formatting of string is not properly aligned in log file result The results looks some thing like this OK move.xml Successful OK AppUser_ifrUsers.asp Successful
14
4301
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my unformatted data values (as decimals) just fine, so I know there's not a problem with the data retrieval, just the formatting. I have read that this would work: lblPrice.Text = prodRow.ToString("C");
6
1696
by: Jack | last post by:
Hi there, Given a standard .NET string, does anyone know what the regular expression would be to locate each (optional) formatting item in the string (or more likely does anyone have a link that will show me this). For instance, given the following simple string: "My phone number is {0} and my SSN is {1}" I want to enumerate (or create a collection of) all formatting items in the
6
4584
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this works fine: Text='<%# Eval("Price", ApplicationContext.CurrencyFormat) %>'
0
8109
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8035
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
8534
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
8509
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
8188
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
6969
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
6034
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
4002
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
4059
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.