473,396 Members | 1,996 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,396 software developers and data experts.

Simple String.Format method question

Hello,

I would like to format the string "11304200" into
"11-3042.00".

Can I do this with String.Format method? I have not come across any good
documentation.

Thank you,

Burak
Nov 20 '05 #1
5 1781
AFAIK, you can't with String.Format.

Try...

s = "11304200"
s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." s.Substring(6)

That what you are looking for?

Mythran
"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
Hello,

I would like to format the string "11304200" into
"11-3042.00".

Can I do this with String.Format method? I have not come across any good
documentation.

Thank you,

Burak


Nov 20 '05 #2
Hi Mythran,

You bring me back to the basics, that is the way I was always doing this
kind of things and now I try to look for things as format, while your code
is in my opinion perfect. (documentates as well very good).

Cor
Try...

s = "11304200"
s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." s.Substring(6)

Nov 20 '05 #3
What exactly is this format ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
Hello,

I would like to format the string "11304200" into
"11-3042.00".

Can I do this with String.Format method? I have not come across any good
documentation.

Thank you,

Burak

Nov 20 '05 #4
Burak,
For documentation on what is allowed & how to use String.Format see:

http://msdn.microsoft.com/library/de...ttingtypes.asp

As you can tell from the above link, .NET does not allow custom formatting
of strings, as does custom formatting of strings really make sense? In cases
where custom formatting of strings does make sense (such as data entry) you
may be able to create a Custom Formatter object (implement the
ICustomFormatter & IFormatProvider interfaces)
http://msdn.microsoft.com/library/de...classtopic.asp
that uses the other string methods to reformat you string.

If your string is truly a number, you might be able to convert it into a
number first then apply one of the above custom numeric formats to the
string.

Hope this helps
Jay

"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
Hello,

I would like to format the string "11304200" into
"11-3042.00".

Can I do this with String.Format method? I have not come across any good
documentation.

Thank you,

Burak

Nov 20 '05 #5

After reading your reply, I noticed an error in my original code...missing an
ampersand :P

s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." & s.Substring(6)

Before the last s.Substring(6) :)

Mythran
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
Hi Mythran,

You bring me back to the basics, that is the way I was always doing this
kind of things and now I try to look for things as format, while your code
is in my opinion perfect. (documentates as well very good).

Cor
Try...

s = "11304200"
s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." s.Substring(6)


Nov 20 '05 #6

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

Similar topics

1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
8
by: Tony | last post by:
Hello I am learning C# and encountered the following problem when I tried to figure out how to print the string {0} in a Console window The following piece of codes complied OK. But when I...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
7
by: Steven D'Aprano | last post by:
I have a sinking feeling I'm missing something really, really simple. I'm looking for a format string similar to '%.3f' except that trailing zeroes are not included. To give some examples: ...
15
by: Fariba | last post by:
Hello , I am trying to call a mthod with the following signature: AddRole(string Group_Nam, string Description, int permissionmask); Accroding to msdn ,you can mask the permissions using...
8
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
5
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
5
by: GregO | last post by:
I am new to ASP and would like to know if anyone has a page that will display username, time, IP TIA - Grego
2
by: pvong | last post by:
Newbie learning VB.Net. I have a simple DataReader and I can grab the info. The data is in numeric format like 123.99 and I want a TextBox to just display it just like that. When I use the code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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...
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,...

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.