|
-
Oct 22nd, 2003, 10:06 AM
#1
Thread Starter
Fanatic Member
[Resolved] Fixed strings for ASP Pages
In ASP .Net, I need to put some values together in a string and then add them to a list box.
I need the individual variables to be 10 characters long and I need them to be right justified.
I tried using this
VB Code:
Dim strName As New String(" ", 10)
And I tried using this...
VB Code:
Dim strName As String = "Right"
In both cases, when I add these variables to a list box there are no spaces in between them...
Here is my listbox add line of code.
VB Code:
ListFuel.Items.Add("RUL " & strGal & " " & strDol & " " & strMar & " " & strPer)
Anyone have any ideas?
Thanks
Last edited by indydavid32; Oct 22nd, 2003 at 12:08 PM.
David Wilhelm
-
Oct 22nd, 2003, 10:15 AM
#2
PowerPoster
Try adding non-breaking spaces ( ) <- Add a semicolon to the end
-
Oct 22nd, 2003, 10:17 AM
#3
You could just use the PadLeft method.
VB Code:
Dim str As String = ListBox1.Items.Count
ListBox1.Items.Add(str.PadLeft(10))
There is also a PadRight if I got the direction mixed up.
-
Oct 22nd, 2003, 10:20 AM
#4
PowerPoster
Originally posted by Edneeis
You could just use the PadLeft method.
VB Code:
Dim str As String = ListBox1.Items.Count
ListBox1.Items.Add(str.PadLeft(10))
There is also a PadRight if I got the direction mixed up.
Because we are dealing with the html, I dont think that will work (didn't try it though).
-
Oct 22nd, 2003, 10:31 AM
#5
Thread Starter
Fanatic Member
Hey guys, thanks for the input.
The padleft doesn't work for ASP pages.
Lethal, since I do not know how many spaces I will need at run time because the values could be from the lenght of 4 (0.00) up to 10, how do you suggest I add the spaces to each of my variables?
Also, how would you get the length of the number? In VB 6 I would simply use len(strVariable) or len(rs.fields("Field_Name"))
Thanks
-
Oct 22nd, 2003, 10:37 AM
#6
PowerPoster
Just create a function that simply subtracts the length of the string from 10, which will give you the amount of spaces to add. To get the length of a number, you will have to convert the int to a string and check the Length property.
Code:
int i = 205;
MessageBox.Show(i.ToString().Length.ToString());
-
Oct 22nd, 2003, 11:34 AM
#7
Thread Starter
Fanatic Member
Lethal, sorry for the newbie questions. I've been using .Net for exactly 3 days. lol
I can't seem to find the wright way to add spaces to my variable so it will show the spaces in my list box.
I am using ASP .Net and VB code in my button click event.
I tried using the as you suggested but can't quite get the syntax down.
Could you show me an example please?
Thanks...
-
Oct 22nd, 2003, 11:41 AM
#8
PowerPoster
Here's an example:
Code:
' We must Decode the text before adding..Dont forget to add
' the semicolons
ListBox1.Items.Add(new ListItem(HttpUtility.HtmlDecode("  Hello")))
-
Oct 22nd, 2003, 11:54 AM
#9
Yeah I missed the ASP.NET part. Here is a web friendly version of the PadLeft:
VB Code:
Dim str As String = ListBox1.Items.Count
ListBox1.Items.Add(HttpUtility.HtmlDecode(str.PadLeft(10).Replace(" ", " "))) 'you'll have to add the ; at the end since it wont let me show that otherwise
-
Oct 22nd, 2003, 12:07 PM
#10
Thread Starter
Fanatic Member
Thanks Edneeis, that's just what I needed!
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
|