locked
personal caracter

    Question

  • Hello

    I need to create a string that is the sum of many strings.

    I want to keep each string separated by a particular caracter something like     string1 & "~" & string2   "~" & string3       etch.

    The problem is that there is the chance that that particular caracter could be  present inside a string.

    Is it possible to create a personal caracter that is not availble on the keybord for this kind of purposes?

    cheers
    Tuesday, June 03, 2008 7:56 PM

Answers

  • You cannot create a new character like that, but you can create an unlikely character combination as your delimeter.

        Private Const SEP As String = "\~%~/"    
                                                                                                                        
        Private Function CombineStrings(ByVal StrArray As String()) As String    
            Dim returnString As String = ""    
            For Each s As String in StrArray    
                If Not returnString = "" Then returnString &= SEP    
                returnString &= s    
            Next s    
            Return returnString    
        End Function    
                                                                                                                        
        Private Function DivideString(ByVal StrToDivide As String) As String()    
            Return Split(StrToDivide, SEP)    
        End Function    


    Another option is to replace your delimeter in the text.  You could change all the ~s to _s.  You'll run into the same dilemma, though -- do you leave all the _s, or convert them all back to ~?  What about _s that were there to begin with?  They'd get changed to ~s.

    • Marked as answer by marck68 Tuesday, June 03, 2008 9:28 PM
    Tuesday, June 03, 2008 8:26 PM
  • You can use any value you like to create a character using the Chr function.  Check out this chart and pick out any value you like (but I wouldn't use 0) . . .
    http://msdn.microsoft.com/en-us/library/aa245259(VS.60).aspx
    • Marked as answer by marck68 Tuesday, June 03, 2008 9:40 PM
    Tuesday, June 03, 2008 8:34 PM
  • You absolutely can do this.  There are a number of ASCII characters that do not have keyboard keys mapped to them.  The only way for the user to type that value is the old ALT+KeyPad combo (and many will not display even that way in most modern text controls).  Besides, most users have no idea that you can even do that. 

    Check out the base ASCII chart.  Most of the numbers 0-31 (decimal) are available for this kind of use - only a few of those are actual format characters.  The others cannot be reproduced from the keyboard (without ALT+KeyPad).  So use Chr(21) or something like that.

    Then, for the fastest way to combine your strings, use String.Join() - assuming you have each value in an array (or can get them into an array).
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marked as answer by marck68 Wednesday, June 04, 2008 5:21 AM
    Tuesday, June 03, 2008 10:37 PM

All replies

  • You cannot create a new character like that, but you can create an unlikely character combination as your delimeter.

        Private Const SEP As String = "\~%~/"    
                                                                                                                        
        Private Function CombineStrings(ByVal StrArray As String()) As String    
            Dim returnString As String = ""    
            For Each s As String in StrArray    
                If Not returnString = "" Then returnString &= SEP    
                returnString &= s    
            Next s    
            Return returnString    
        End Function    
                                                                                                                        
        Private Function DivideString(ByVal StrToDivide As String) As String()    
            Return Split(StrToDivide, SEP)    
        End Function    


    Another option is to replace your delimeter in the text.  You could change all the ~s to _s.  You'll run into the same dilemma, though -- do you leave all the _s, or convert them all back to ~?  What about _s that were there to begin with?  They'd get changed to ~s.

    • Marked as answer by marck68 Tuesday, June 03, 2008 9:28 PM
    Tuesday, June 03, 2008 8:26 PM
  • You can use any value you like to create a character using the Chr function.  Check out this chart and pick out any value you like (but I wouldn't use 0) . . .
    http://msdn.microsoft.com/en-us/library/aa245259(VS.60).aspx
    • Marked as answer by marck68 Tuesday, June 03, 2008 9:40 PM
    Tuesday, June 03, 2008 8:34 PM
  • One other thought is that if your individual strings do not have line breaks in them, you can use line breaks to separate them.

    Dim compositeString As String = string1 & Environment.NewLine & string2   
    & Environment.NewLine & string3 

    If you're going to use Environment.NewLine a lot, you might want to declare a Constant.  I often declare ENL = Environment.NewLine, just so I don't have to type it out and moreso to keep the code shorter and more readable (to me, anyway).
    Tuesday, June 03, 2008 8:43 PM
  • Is a line break equivalent to a return???
    Tuesday, June 03, 2008 9:30 PM
  • You absolutely can do this.  There are a number of ASCII characters that do not have keyboard keys mapped to them.  The only way for the user to type that value is the old ALT+KeyPad combo (and many will not display even that way in most modern text controls).  Besides, most users have no idea that you can even do that. 

    Check out the base ASCII chart.  Most of the numbers 0-31 (decimal) are available for this kind of use - only a few of those are actual format characters.  The others cannot be reproduced from the keyboard (without ALT+KeyPad).  So use Chr(21) or something like that.

    Then, for the fastest way to combine your strings, use String.Join() - assuming you have each value in an array (or can get them into an array).
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marked as answer by marck68 Wednesday, June 04, 2008 5:21 AM
    Tuesday, June 03, 2008 10:37 PM
  •  is the quanitity of memory used by each caracter equivalent or do they use different quantity of memory??
    Wednesday, June 04, 2008 5:22 AM
  • Any given character (Char object) will always be 2 bytes in size.

    And on your previous question, yes, for the most part a "line break" is equivalent to a "return".  Just keep in mind that in Win32 a standard return is equal to two characters:  CR (13h) + LF (10h)


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Wednesday, June 04, 2008 4:59 PM