473,408 Members | 2,441 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,408 software developers and data experts.

Formatting strings in VB.NET

I have seen lots of information in help and in here about formatting
numbers and dates, but what about strings?

In VB6 I could do something like this...

Format("abcdefghi","@@@-@@-@@@@")

....and the result would be...

abc-de-fghi

How can I do this in VB.NET? I have looked at .ToString, and it just
referes to numeric formats and data time formats. I can't find how to
format strings.

Thanks for any help.

RichardF
Nov 21 '05 #1
2 1322
On Mon, 14 Mar 2005 13:32:11 -0600, RichardF <no***@nowhere.com> wrote:

¤ I have seen lots of information in help and in here about formatting
¤ numbers and dates, but what about strings?
¤
¤ In VB6 I could do something like this...
¤
¤ Format("abcdefghi","@@@-@@-@@@@")
¤
¤ ...and the result would be...
¤
¤ abc-de-fghi
¤
¤ How can I do this in VB.NET? I have looked at .ToString, and it just
¤ referes to numeric formats and data time formats. I can't find how to
¤ format strings.

Here is one way it can be done:

Dim StringVal As String = "abcdefghi"
Dim FormattedStringVal As String
FormattedStringVal = StringVal.Format("{0}-{1}-{2}", StringVal.Substring(0, 3),
StringVal.Substring(3, 2), StringVal.Substring(5, 4))
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #2
That would work, but that woud mean coding for every possible
variation of format mask or rewriting the Format function myself in
VB.NET.

This was something that was so easy in VB6, surely there must be a way
to do it in .NET too!

RichardF

On Mon, 14 Mar 2005 14:26:14 -0600, Paul Clement
<Us***********************@swspectrum.com> wrote:
On Mon, 14 Mar 2005 13:32:11 -0600, RichardF <no***@nowhere.com> wrote:

¤ I have seen lots of information in help and in here about formatting
¤ numbers and dates, but what about strings?
¤
¤ In VB6 I could do something like this...
¤
¤ Format("abcdefghi","@@@-@@-@@@@")
¤
¤ ...and the result would be...
¤
¤ abc-de-fghi
¤
¤ How can I do this in VB.NET? I have looked at .ToString, and it just
¤ referes to numeric formats and data time formats. I can't find how to
¤ format strings.

Here is one way it can be done:

Dim StringVal As String = "abcdefghi"
Dim FormattedStringVal As String
FormattedStringVal = StringVal.Format("{0}-{1}-{2}", StringVal.Substring(0, 3),
StringVal.Substring(3, 2), StringVal.Substring(5, 4))
Paul
~~~~
Microsoft MVP (Visual Basic)


Nov 21 '05 #3

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

Similar topics

11
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...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
4
by: Robert Manookian | last post by:
How do you format strings? i.e. In VB6: Format("AB34567", "@@@@@-@@") = "AB345-67" In .Net: ????????
2
by: David Veeneman | last post by:
How does one format a date column in a GridView control? I had assumed that the DataFormat string would do it, but MSDN only shows numeric formatting codes. Can dates be formatted using that...
4
by: Peter Newman | last post by:
the data input app im writing has some 30 + input fields and i want to be able to format them. I know i can use the .validate on each textbox and format the 'string' however this require loads...
11
by: Dustan | last post by:
Is there any builtin function or module with a function similar to my made-up, not-written deformat function as follows? I can't imagine it would be too easy to write, but possible... 'I am...
9
by: john coltrane | last post by:
Is there way to create a formatted string in a similar that is similar to sprintf? The same for printing, printf? C,D,E,F,G,N,X for currency, decimal, exponential, fixed, general, numerical,...
6
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...
2
by: Jean-Paul Calderone | last post by:
On Fri, 5 Sep 2008 14:24:16 -0500, Robert Dailey <rcdailey@gmail.comwrote: mystring = ( "This is a very long string that " "spans multiple lines and does " "not include line breaks or tabs "...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
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
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
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...

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.