473,847 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1797
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*********@xp andcorp.com> wrote in message
news:b1******** *************** ***@posting.goo gle.com...
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*********@xp andcorp.com> wrote in message
news:b1******** *************** ***@posting.goo gle.com...
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
ICustomFormatte r & 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*********@xp andcorp.com> wrote in message
news:b1******** *************** ***@posting.goo gle.com...
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**********@p lanet.nl> wrote in message
news:e6******** ******@TK2MSFTN GP12.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
1790
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> <OnCallPerson /> <CallType>Exposure</CallType> <ExposureReason>General</ExposureReason> <OtherExposureReason>Unintentional</OtherExposureReason> <ClientName>Test Client</ClientName>
8
3360
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 ran it, it failed The codes are using System class Test
1
1554
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 get it to recieve only one line of data, but the next one i send to it wont be printed like the 1st one. I had a listner running in a thread, does anyone have a simple listner code example that would show how to have a tcplistner thread running...
7
1708
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: Float String 1.0 1
15
3089
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 pipe symbol .for example you can use something like this AddRole("My Group", "Test", 0x10000000|0x00000002);
8
3561
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 simple' problem... I can create a database 'test.db', add a table 'foo' (which BTW I repeatedly DROP on each run) with one INTGER column 'id', and can insert data into with: cur.execute("INSERT INTO foo (id) VALUES (200)") con.commit()
5
2323
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
2842
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
3846
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 below, I get 123.9900 and I don't know how to get rid of the last 2 zeros. I thought for sure the below would work but it didn't. Thanks in advance. ---------------------- Dim AmountMoney As Decimal = CType(dr.Item("Amount"), Decimal)
0
9886
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
10647
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
10706
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
10338
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
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5719
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
5910
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4527
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
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.