Results 1 to 10 of 10

Thread: [Resolved] Fixed strings for ASP Pages

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    [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:
    1. Dim strName As New String(" ", 10)

    And I tried using this...

    VB Code:
    1. 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:
    1. 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

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try adding non-breaking spaces (&nbsp) <- Add a semicolon to the end

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You could just use the PadLeft method.
    VB Code:
    1. Dim str As String = ListBox1.Items.Count
    2.         ListBox1.Items.Add(str.PadLeft(10))
    There is also a PadRight if I got the direction mixed up.

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Originally posted by Edneeis
    You could just use the PadLeft method.
    VB Code:
    1. Dim str As String = ListBox1.Items.Count
    2.         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).

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    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
    David Wilhelm

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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());

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    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 &nbsp; as you suggested but can't quite get the syntax down.

    Could you show me an example please?

    Thanks...
    David Wilhelm

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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("&nbsp&nbspHello")))

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yeah I missed the ASP.NET part. Here is a web friendly version of the PadLeft:
    VB Code:
    1. Dim str As String = ListBox1.Items.Count
    2.         ListBox1.Items.Add(HttpUtility.HtmlDecode(str.PadLeft(10).Replace(" ", "&nbsp"))) 'you'll have to add the ; at the end since it wont let me show that otherwise

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Talking

    Thanks Edneeis, that's just what I needed!
    David Wilhelm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width