Results 1 to 12 of 12

Thread: Safe String Code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Safe String Code

    Hey,

    How to make function which removes all unsafe charters, removes spaces, converts international letter to latin etc, and retuns only latin letters and numbers (alphasimbols)?

    Also this function should reduce lenght of the string to n simbols.

    ETC.:

    dim str as string = "<*> Hello 10 people, how are you!? <*>"
    str = myfunction(str, 8)

    And then Str value is equl to = "he10phay"
    If lengt of string is more then 8 after removing unsafe charters, it cuts some characters of every world until it's lengt is 8.

    Any suggestions?

    Maybe .NET has function which convers string to alpha string?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't know how to do that but Regular Expression can help you .

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Safe String Code

    Originally posted by Norkis
    Hey,

    How to make function which removes all unsafe charters, removes spaces, converts international letter to latin etc, and retuns only latin letters and numbers (alphasimbols)?

    Also this function should reduce lenght of the string to n simbols.

    ETC.:

    dim str as string = "<*> Hello 10 people, how are you!? <*>"
    str = myfunction(str, 8)

    And then Str value is equl to = "he10phay"
    If lengt of string is more then 8 after removing unsafe charters, it cuts some characters of every world until it's lengt is 8.

    Any suggestions?

    Maybe .NET has function which convers string to alpha string?
    Heavens! Your mind is even more twisted than mine Let's have a go.

    1. "How to make function which removes all unsafe charters, removes spaces,"

    Compare each character with the appropriate range of ASCII values and reject as necessary.

    2. "converts international letter to latin etc, and retuns only latin letters and numbers (alphasimbols)?"

    Not sure what you mean. i.e. convert e.g. Cyrillic script to Latin? Convert Arabic to Latin? Convert Chinese to Latin?

    3. "Also this function should reduce lenght of the string to n simbols"

    Find the length of the converted string: divide it by n: get each n th character from the string.

    May I ask the purpose of this?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    I'm creating universal registration form, whis stores all data in DB.

    Then user create new field, he enters it's title.
    Title can consist anything, like "‡ Surname (Pavardë) Ñ"
    I cant create table with column name like this title, so I want to convert it so safe, but readable for me.

    Hum, I think it would be large funtion, with several loops...
    No way to make it shorter?

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Norkis
    I'm creating universal registration form, whis stores all data in DB.

    Then user create new field, he enters it's title.
    Title can consist anything, like "‡ Surname (Pavardë) Ñ"
    I cant create table with column name like this title, so I want to convert it so safe, but readable for me.

    Hum, I think it would be large funtion, with several loops...
    No way to make it shorter?
    But surely the user will want to see the field name as he originally entered it? So, why not create a table which holds in one column the name as entered (as many characters as entered); in another column the name you allocated (8 characters long); in another column the table to which the names refer. Then, when you want to display the information in future, you simply have to cross reference.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Wink

    This is exactly what I'm doing.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Norkis
    This is exactly what I'm doing.
    Then the quickest way would be to keep note of how many columns are being created and name them Column1, Column2 ..etc e.g. strCol="Column" & str(val(iCol)) (or use casting if you prefer)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    But then it would be harder, if I have to modify something manualy.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Norkis
    But then it would be harder, if I have to modify something manualy.
    Sorry, I don't follow you. You will have just simplified the way of naming your data table column. Nothing else will be different.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    Ok. I tryied to name my columns in simple way (column1, column 2 ...)

    Now I got new problem:

    Imagine, That I create two fileds (columns).
    It will be Column1 and Column2 (Column name consists word "Column" & item.index in datalist)
    Then I remove the first one, so there are only Column2 left.
    I got error, when I try to add new one, becource the name Column2 already exist.

    How to solve this?

  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Norkis
    Ok. I tryied to name my columns in simple way (column1, column 2 ...)

    Now I got new problem:

    Imagine, That I create two fileds (columns).
    It will be Column1 and Column2 (Column name consists word "Column" & item.index in datalist)
    Then I remove the first one, so there are only Column2 left.
    I got error, when I try to add new one, becource the name Column2 already exist.

    How to solve this?
    hI,

    How about using an autonumber as your key field in the reference table we referred to and using that as the addition to "Column"
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Wink

    Good idea! Thanks

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