|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Formatting text w/VB.NETHow do you format text in VB.NET? In VB6, I'd use something like:
format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it was only 3 (for example). This simple convention apparently doesn't exist in VB.NET. I've looked all around and I can't find a single example on how you would code this in VB.NET. Anyone have an example they can share or point me to some examples? Thanks, Mark Mark Brown wrote:
> How do you format text in VB.NET? In VB6, I'd use something like: String.Format(...)> format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it was only > 3 (for example). This simple convention apparently doesn't exist in VB.NET. > I've looked all around and I can't find a single example on how you would > code this in VB.NET. Anyone have an example they can share or point me to > some examples? > > Thanks, > Mark > > Didn't work. I tried that with a string 7 chars long, tried to format it so
that it would always be at least 10 chars and it still only formatted to 7 chars. Show quoteHide quote "Chris" <no@spam.com> wrote in message news:44FEFB0E.1020505@spam.com... > Mark Brown wrote: >> How do you format text in VB.NET? In VB6, I'd use something like: >> format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it was >> only 3 (for example). This simple convention apparently doesn't exist in >> VB.NET. I've looked all around and I can't find a single example on how >> you would code this in VB.NET. Anyone have an example they can share or >> point me to some examples? >> >> Thanks, >> Mark > > String.Format(...) Mark Brown wrote:
Show quoteHide quote > Didn't work. I tried that with a string 7 chars long, tried to format it so What did you try? Can you show the code? Remember that strings in> that it would always be at least 10 chars and it still only formatted to 7 > chars. > > "Chris" <no@spam.com> wrote in message news:44FEFB0E.1020505@spam.com... > > Mark Brown wrote: > >> How do you format text in VB.NET? In VB6, I'd use something like: > >> format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it was > >> only 3 (for example). This simple convention apparently doesn't exist in > >> VB.NET. I've looked all around and I can't find a single example on how > >> you would code this in VB.NET. Anyone have an example they can share or > >> point me to some examples? > >> > >> Thanks, > >> Mark > > > > String.Format(...) ..Net are immutable and cannot be changed so methods like Format return a new string. To format like you want you would do something like this: Dim s As String = "Hello" s = String.Format("{0,-10}", s) This line tells it to format the string, making it 10 characters if the string is less than 10 characters. The minus sign tells it to left justify the text. If you want it right justified, remove the minus sign. You can also do something like this: Dim sName As String = "Mark" Dim sResult As String = String.Format("Hello there {0,-10}", sName) sResult would contain: "Hello there Mark " Hope this helps Chris Dunaway wrote:
Show quoteHide quote > Mark Brown wrote: I should have pointed out that you can use multiple argument to the> > Didn't work. I tried that with a string 7 chars long, tried to format it so > > that it would always be at least 10 chars and it still only formatted to 7 > > chars. > > > > "Chris" <no@spam.com> wrote in message news:44FEFB0E.1020505@spam.com... > > > Mark Brown wrote: > > >> How do you format text in VB.NET? In VB6, I'd use something like: > > >> format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it was > > >> only 3 (for example). This simple convention apparently doesn't exist in > > >> VB.NET. I've looked all around and I can't find a single example on how > > >> you would code this in VB.NET. Anyone have an example they can share or > > >> point me to some examples? > > >> > > >> Thanks, > > >> Mark > > > > > > String.Format(...) > > What did you try? Can you show the code? Remember that strings in > .Net are immutable and cannot be changed so methods like Format return > a new string. To format like you want you would do something like > this: > > Dim s As String = "Hello" > > s = String.Format("{0,-10}", s) > > This line tells it to format the string, making it 10 characters if the > string is less than 10 characters. The minus sign tells it to left > justify the text. If you want it right justified, remove the minus > sign. > > You can also do something like this: > > Dim sName As String = "Mark" > Dim sResult As String = String.Format("Hello there {0,-10}", sName) > > sResult would contain: "Hello there Mark " > > Hope this helps Format command like this: Dim sFirstName As String = "Mark" Dim sLastName As String = "Brown" Dim sResult As String sResult = String.Format("First Name: {0,-10} Last Name: {1,-10}", sFirstName, sLastName) Notice that the 0 and 1 in the format specifiers are indexes to the arguments passed into the Format method. 0 corresponds to the sFirstName, 1 corresponds to the last name. You can use them more then once in a format too like this: Dim sFirstName As String = "Mark" Dim sLastName As String = "Brown" Dim sResult As String sResult = String.Format("First Name: {0,-10} Last Name: {1,-10} Full Name: {0} {1}", sFirstName, sLastName) Notice how I used the 0 and 1 indexes in the string format. Well, I don't know what I did wrong the first time, but I tried it again and
it worked just fine. Thanks! Mark Show quoteHide quote "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1157572284.553191.59450@m79g2000cwm.googlegroups.com... > Mark Brown wrote: >> Didn't work. I tried that with a string 7 chars long, tried to format it >> so >> that it would always be at least 10 chars and it still only formatted to >> 7 >> chars. >> >> "Chris" <no@spam.com> wrote in message news:44FEFB0E.1020505@spam.com... >> > Mark Brown wrote: >> >> How do you format text in VB.NET? In VB6, I'd use something like: >> >> format(foo,"!@@@@@@@@") to get a string to fill 8 places even if it >> >> was >> >> only 3 (for example). This simple convention apparently doesn't exist >> >> in >> >> VB.NET. I've looked all around and I can't find a single example on >> >> how >> >> you would code this in VB.NET. Anyone have an example they can share >> >> or >> >> point me to some examples? >> >> >> >> Thanks, >> >> Mark >> > >> > String.Format(...) > > What did you try? Can you show the code? Remember that strings in > .Net are immutable and cannot be changed so methods like Format return > a new string. To format like you want you would do something like > this: > > Dim s As String = "Hello" > > s = String.Format("{0,-10}", s) > > This line tells it to format the string, making it 10 characters if the > string is less than 10 characters. The minus sign tells it to left > justify the text. If you want it right justified, remove the minus > sign. > > You can also do something like this: > > Dim sName As String = "Mark" > Dim sResult As String = String.Format("Hello there {0,-10}", sName) > > sResult would contain: "Hello there Mark " > > Hope this helps >
SQL parameter: what is wrong here?
Registry Reading Remove certain characters from a string/RichTextBox? Abstraction question Calling a VB.NET-DLL FROM VB6 Iterating through the records in a dataset Crystal Reports in VB.NET Determining max number of characters in a TextBox how to get a file to display from relative filespec Deleting a folder |
|||||||||||||||||||||||