Results 1 to 18 of 18

Thread: New name for string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    83

    New name for string

    In my project I need to use a 190 very long strings with different number of characters (4-60).
    I want to mark them in a short form with the numbers 001, 002, 003 ... 190.
    Is there an easy way to display the full name of the string when I choose a short name ?
    Of course, I do not want to write 190 times "if - end if" and also I would like to avoid a complicated database.
    Onenew
    Visual Studio 2010

  2. #2
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: New name for string

    I need to use a 190 very long strings with different number of characters (4-60).
    is this mean strings of variable length wright ?
    I want to mark them in a short form with the numbers 001, 002, 003 ... 190.
    what are these numbers, is it just like person & his ID. like 001 = string1

    if so
    there are 2 ways,
    (1) Use a simple database ( access is preferable )
    (2) load all the data in to a datatable & query it
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    83

    Re: New name for string

    More explanations. Strings have variable lengths.
    For example:
    001 = 1-8,2-9,3-10
    002 = 1-10
    003 = 1-6,8,10,12,14,16,18,20,22,24,26,28,30
    Onenew

  4. #4
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: New name for string

    fine
    create a access database, & store these values and then query it.
    what help you need here
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  5. #5
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    278

    Re: New name for string

    Surely you could just put them in an array?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    83

    Re: New name for string

    Hi, OhGreen,
    Can you say something a little more about it and maybe give an example?
    Onenew

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: New name for string

    Surely you just need a dictionary.

    Code:
    Dim Data As New Dictionary(Of String, String)
    
    Data.Add("001", "blah blah long string blah blah")
    Data.Add("002", "Other long blah blah long string blah blah")
    Data.Add("003", "Other other long blah blah long string blah blah")
    You can then just pull them out when you need them like so:

    Code:
    MessageBox.Show( Data("001") )
    
    MessageBox.Show( Data("003") )

  8. #8
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    278

    Re: New name for string

    Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list. You could use either method.

    OneNew, how are you planning on:

    a) changing the strings in the future (if necessary?)
    b) entering the value initially

    It would be possible using Grimfort's example to add features to delete or add items.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: New name for string

    I'd go with the dictionary, too. They are very convenient. You can also work with either just the keys or just the values, so it is probably your most versatile alternative.
    My usual boring signature: Nothing

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: New name for string

    Quote Originally Posted by OhGreen View Post
    Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list. You could use either method.

    OneNew, how are you planning on:

    a) changing the strings in the future (if necessary?)
    b) entering the value initially

    It would be possible using Grimfort's example to add features to delete or add items.
    I don't think that's valid. Using a dictionary by any means, especially the way Grimfort did, it doesn't matter whether the items shift. In fact, it's hard to say that they would shift at all. They are key-value pairs. The key remains tied to the same value, regardless of whether you add or remove items. Item #10 may have the key "011". If you were to remove item #9, then Item#10 would become item #9, but it would still have the key "011", and would still have the associated value. You wouldn't normally use an index value (such as my #9 and #10) to access an item in a dictionary, but if you wanted to do that, then the dictionary should be a Dictionary (of Integer,String) where the integer is the same as the index. This could be done, but there isn't any sound reason to do so.
    My usual boring signature: Nothing

  11. #11
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: New name for string

    Quote Originally Posted by OhGreen View Post
    Fair point Grimfort, the only problem would be if you deleted a string from the dictionary it would shift the remaining items within the list.
    This is not a problem, this is the design of a Dictionary. If position is important, you don't use a Dictionary, you use an actual List, but that defeats the whole lookup idea.

  12. #12
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: New name for string

    i prefer to load the data in to a datatable & then query the same
    please find the attachment,

    how ever i failed to set the LINQ out put as datagridview datasource Grim any advice further in this context
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  13. #13
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    278

    Re: New name for string

    Oh right okay, I've never really played with dictionary's simply because of knowing that they shift the position and presumed that would be an issue in most examples.

    Wouldn't that then make arrays redundant? Or am I completely off when thinking they're very similar?

  14. #14
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    278

    Re: New name for string

    make_me_rain I personally agree, with the amount of data involved in this situation I'd rather have the strings stored within a database. Although with the vast amount it would make the code mammoth, you do have the option of creating a module to hide the bulk of the dictionary.

  15. #15
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: New name for string

    190 strings is quite small, I have resource files with far far more entries than this. If this is just information you are spraying around like error codes, then a resource file is just as useful. Likely adding a database to this scenario will hit your 190 lines on its own .

  16. #16
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: New name for string

    grim,Og my highlighted part is leftover
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  17. #17
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: New name for string

    I did not have any time to look at it, sorry!

  18. #18
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: New name for string

    oh, ok
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

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