|
-
Aug 14th, 2011, 10:28 AM
#1
Thread Starter
Hyperactive Member
Setting Tab Stops for Strings
This is in a RichTextBox.
I'm making a string of sports stats and I need to have them aligned neatly in the RichTextBox. Here is an example:
str = "12/24 (tab) 225 yards (tab) 2 TDs (tab) 2 INTs"
When I use the vbTab constant in place of (tab) I run into problems as the size of the text in each column can be different which makes the tab not balance out correctly.
I need to stop specifically at say, the 50th character no matter what the length of the characters before it. Something like TAB() for printing but this doesn't seem to work for strings.
Thanks,
neef
Intermediate Level Programmer Extraordinaire 
-
Aug 14th, 2011, 11:15 AM
#2
Member
Re: Setting Tab Stops for Strings
You could be use repeated blanks instead, eg:
Code:
Dim txt As String = "12/24" & StrDup(8, " "c) & "225 yards" & StrDup(8, " "c) & "2 TDs" & StrDup(8, " "c) & "2 INTs"
Me.RichTextBox1.Text = txt
See if this will be looking better
-
Aug 14th, 2011, 12:17 PM
#3
Re: Setting Tab Stops for Strings
Code:
Dim Rows As String() = _
{ _
String.Concat("5/24".TabStop, "5 yards".TabStop, "112 TDs".TabStop, "11"), _
String.Concat("12/24".TabStop, "225 yards".TabStop, "2 TDs".TabStop, "11"), _
String.Concat("1".TabStop, "2".TabStop, "3".TabStop) _
}
For Each row In Rows
Console.WriteLine("[{0}]", row)
Next
For Each row In Rows
If row.Length > 50 Then
Console.WriteLine("[{0}]", row.Substring(0, 49))
Else
Console.WriteLine("[{0}]", row)
End If
Next
The following goes into a code module
Code:
<System.Diagnostics.DebuggerStepThrough()> _
<System.Runtime.CompilerServices.Extension()> _
Function TabStop(ByVal value As String) As String
Return value & System.Text.RegularExpressions.Regex.Unescape("\t")
End Function
-
Aug 14th, 2011, 12:22 PM
#4
Thread Starter
Hyperactive Member
Re: Setting Tab Stops for Strings
This wasn't an exact solution but it set me in the right direction. I just needed to do some figuring to determine the correct value of StrDup's first input (instead of a 8 or 6 or whatever). I wanted the total spaces including the text to be 12; I subtracted 12 minus the string length and used that number as the number of duplicate spaces.
Works like a charm now, thanks!
One question, in StrDup(8, " "c) what is the c after the quotes for? That is new to me and I'm curious.
Intermediate Level Programmer Extraordinaire 
-
Aug 14th, 2011, 12:47 PM
#5
Re: Setting Tab Stops for Strings
Kind of a pain to do all that just to duplicate the functionality of a ListView (in detail mode) in an RTB. Is there a reason why you have to do it that way?
My usual boring signature: Nothing
 
-
Aug 14th, 2011, 02:17 PM
#6
Member
Re: Setting Tab Stops for Strings
 Originally Posted by neef
This wasn't an exact solution but it set me in the right direction. I just needed to do some figuring to determine the correct value of StrDup's first input (instead of a 8 or 6 or whatever). I wanted the total spaces including the text to be 12; I subtracted 12 minus the string length and used that number as the number of duplicate spaces.
Works like a charm now, thanks!
One question, in StrDup(8, " "c) what is the c after the quotes for? That is new to me and I'm curious.
this means a char - (c)
-
Aug 14th, 2011, 02:33 PM
#7
Re: Setting Tab Stops for Strings
Type Characters. Appending the literal type character C to a single-character string literal forces it to the Char data type. Char has no identifier type character.
http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
-
Aug 14th, 2011, 02:43 PM
#8
Thread Starter
Hyperactive Member
Re: Setting Tab Stops for Strings
 Originally Posted by Shaggy Hiker
Kind of a pain to do all that just to duplicate the functionality of a ListView (in detail mode) in an RTB. Is there a reason why you have to do it that way?
That's a good question. I didn't want a spreadsheet look, but rather a newspaper style.
Intermediate Level Programmer Extraordinaire 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|