Results 1 to 16 of 16

Thread: .Net "String" equivalent

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Question .Net "String" equivalent

    How do you do the following in VB.NET:


    Dim mystring as string * 25


    I thought it may be

    Dim mystring as new string("",25)

    But I think I may be mistaken..

    Thanks
    Tom

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I think

    Dim mystring As New String("",0,25)

    will work
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Thumbs down Ouch

    Tried that,
    Dim SDEPT As New String("", 0, 25)


    Got:

    An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in HelloWorld.exe

    Additional information: Index was out of range. Must be non-negative and less than the size of the collection.


    Any more ideas?


  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    <VBFixedString(25)> Public buffer As String
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Red face Thanks But..

    Dander,

    Thanks, I should have seen that in the MSDN..

    Still not quite "right"

    in VB 6.0:
    Dim stringa As String
    Dim stringb As String * 25

    stringa = "TEST"
    stringb = stringa

    MsgBox " ' " & stringb & " ' "

    The message box would show something like:

    'TEST '

    Showing the whole 25 positions.

    Doing the same .Net I am still getting:

    'TEST'

    Even with the declared length.

    Bummer I need to get it as such for some keyed reads..

    Tom


    I tried it, and when I did a message box on it:

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Angry Darn display!

    Dander

    The "TEST" example did not display right..


    In VB 6.0 I would see "TEST" with the balance of the 25 positions in the msgbox

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Well I dont know then..
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Thumbs up Thanks

    Thanks for the help anyway, I still "learned something"

    Maybe someone else can find the missing clue?

    Tom

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    perhaps tell us what you are trying to do that you need fixed length strings. There maybe another way
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Red face A apology


    Cander,

    oops, I was calling you "Dander"! Sorry about that, what the heck was I looking at!!

    Tom

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913


    LOL. Its ok.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Talking

    Well

    For one thing I got data in Oracle tables that have trailing
    spaces:


    fieldx = "somevalue<SPACE><SPACE><Etc>"

    so when I do a SQL command I need the key value to reflect that fact.

    The other thing I was trying to do is to create a menu selection in a list box with the menu "option number" portion of the string I am adding to the listbox as being the current index value. I want the index value to be part of concatenated field of fixed length 2 padded left to line it up:


    dim str_optionnumber as string * 2
    dim str_text as string
    dim str_combined as string
    dim index as integer

    index = 1
    str_text = "Reports Menu"
    str_optionnumber = index

    str_combined = str_optionnumber.padleft(2) & "." & space(1) & str_text


    listbox1.items.add(str_combined)

    result:

    1. Reports Menu

    add the reset:

    2. blah
    "
    "
    10. blah


    the menu selections would be in alignment.

    If any other ideas please let me know; this IS tedious!

  13. #13
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hmm..well perhaps look into the stringbuilder class. I think you can set some fixed length there..dont know if it will accomplish hat you need though.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  14. #14
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    arg stringbuilder doesnt work either. I tried it.

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  15. #15
    Member
    Join Date
    Sep 2002
    Posts
    37
    There are no fixed lentgh strings in .net


    Try PadRight.


    Dim strW As String
    strW = "A"
    strW = StrW.PadRight(25," ")
    MessageBox.Show(Len(strW))


    The Length of strW should be 25.


    Harold Hoffman

  16. #16
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yeah, but the VBFixedString attribute is supposed to emulate it. but it doesnt work.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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