Results 1 to 17 of 17

Thread: ARGH! How the hell do you remove a character from a string... (STILL UNRESOLVED)

  1. #1

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68

    ARGH! How the hell do you remove a character from a string... (STILL UNRESOLVED)

    Ok, this is really starting to bug me...

    How do you remove a character from a string WITHOUT replacing the whole string? I've printed an example below.

    This is the text I want to change. I've split it into the sections it's sent in, and each section is searched before it's appendeed to the end.
    Code:
    ÿ‚[N 10:48am 150/150hp 504/504m 706mv 1000xp> ÿù
    Code:
    ÿ‚[N 10:48am 150/150hp 504/504m 706mv 1000xp> ÿùThere is 1 character on you can see (yourself).
    The most characters on since the last reboot has been 2.
         
    =========---=========           Vinarian Legends          =========---=========
    =========---=========         "Dream the Dream..."        =========---=========
    
                                 -=-=-=-=-=--=-=-=-=-=-
    
    =========---=========          I m m o r t a l s          =========---=========
    =========---=========             O n l i n e             =========---=========
         <***> Tiiyakanah de Tera, Bringer of Chaos and Order (H)
         
                                 -=-=-=-=-=--=-=-=-=-=-
    
    =========---=========            M o r t a l s            =========---=========
    =========---=========             O n l i n e             =========---=========
    For more info on maxon and other mud related stats type mudstats.
    
    ÿ‚[N 10:48am 150/150hp 504/504m 706mv 1000xp> ÿù
    Code:
    --13:20:55--ticks--> TICK!
    
    ÿ‚[N 10:48am 150/150hp 504/504m 706mv 1000xp> ÿù
    So each one of those 'code' bits ('s really just there coz it's a monotyped font) is a seperate string, but when appended to the end of an rtf text box, they make up the entire string. But anyway, as each section comes in, I want to search it for escape sequences (not shown, but they're chr(27) and [) and those annoying y and u things...

    And ideas? Oh, and this text ocmes in through Winsock's Recv function if that's any help.

    Thanks.
    Last edited by esmerelda; Oct 31st, 2002 at 11:19 AM.

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Not sure at all what do you want to "remove" but there is a Replace function in VB6 to replace text with some other text:
    strNewText = Replace(strOldText,"search_char","replace_char")
    In your case (I guess) "replace_char" should be empty string.
    Roy

  3. #3
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    You could use the replace function on the incoming strings

    VB Code:
    1. textToAdd = Replace(textToAdd, chr(27), "")

    And just do this repeatedly to remove any character you want.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  4. #4
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    How do you remove a character from a string WITHOUT replacing the whole string
    you're working in VB now, not C. I C you could find the character you want to delete and do a move to bring the rest of the string left one char, but in VB you can't do that, you have to do what I assume you mean by "replace the whole string". If you're putting everything somewhere else anyway, then that's a different story, since you can just transfer up to the bad char and then transfer after the bad char and you're not replacing anything.

  5. #5
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    and by the way, chr(27) is ESC, and those strings are called "ESCape strings" --- they're used by printers and other things as control sequences.

  6. #6
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I just erad your post again and here is what I think: you're actually looking for a way to replace binary characters ("ÿ" and "ù", etc...). I don't believe Replace function will do the job quite correctly simply because god only nows what those chars really are. So you may end up with looking for something that doesn't exist (unless you convert those chars to an ASCII code).
    Roy

  7. #7

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Originally posted by phinds
    and by the way, chr(27) is ESC, and those strings are called "ESCape strings" --- they're used by printers and other things as control sequences.
    I know that you twot, why do you think I typed chr(27) instead of ESC? Because most people don't know what the hell I'm on about if I do *pokes you hard*

  8. #8

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Originally posted by IROY55
    I just erad your post again and here is what I think: you're actually looking for a way to replace binary characters ("ÿ" and "ù", etc...). I don't believe Replace function will do the job quite correctly simply because god only nows what those chars really are. So you may end up with looking for something that doesn't exist (unless you convert those chars to an ASCII code).
    What I want to do is replace certain sets of characters, ESCape codes *glares* and those annoying extended ascii codes, to RTF colour codes and blank spaces respectively. How do you replace them, or remove them by replacing them with "" 's easily? Are you seriously saying there is no way of ever removing the anomolous characters easily? (Anomolous means ones which aren't normal/wanted).

  9. #9
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373
    can you save in a text file the string "as is"?
    I work with strings that contains control codes like Cr, Lf, STX, ETX, EOT, etc., and the same method that I posted at your other thread asking this...is the one that I use...

    post in a zip file the text file and tell me what are the strings that you don't want and I'll make you something that will work with your "real" data...
    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

  10. #10
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    ... Are you seriously saying there is no way of ever removing the anomolous characters easily? ...
    That's exactly right, unfirtunately. The real problem is that you don't know what to look for as those Binary/Unicode characters are unknown yet as you will have to "translate" (convert if you will) them (if it is possible at all).
    Roy

  11. #11

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Originally posted by D12Bit
    can you save in a text file the string "as is"?
    I work with strings that contains control codes like Cr, Lf, STX, ETX, EOT, etc., and the same method that I posted at your other thread asking this...is the one that I use...

    post in a zip file the text file and tell me what are the strings that you don't want and I'll make you something that will work with your "real" data...
    Yep. I've logged a session to a text file and attached it.

    Oh, and if you take off the .txt extension, it'll show the actual rtf file.
    Attached Files Attached Files

  12. #12
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    I do actually know what you want to do. Is it to just get rid of the characters in place, is this what you mean by not replacing the whole string. If so then just scan the data and replace any non-ASCII characters with spaces (Of course, not cr, lf, tabs). You will need to write a function to do this. I do have such a function if you would like it.

    Use the following functions to determine if the character is ASCII and then replace it with a space

    Hopefully I was of some help.
    VB Code:
    1. Const AsciiChars = "abcdefghijklmnopqrstuvwxyz,./<>?;':[]{}\|1234567890-=!@#$%^&*()_+`~ABCDEFGHIJKLMNOPQRSTUVWXYZ "
    2.  
    3. Public Function StrTrans(txt as string) as string
    4. dim newstr as string
    5.  
    6.    newstr=newstr
    7.    for i = 1 to len(newstr)
    8.       char = mid(newstr,i,1)
    9.       if not isascii(char) then mid(newstr,i,1) = " "
    10.    next i  
    11.  
    12. StrTrans = newstr
    13. End Function
    14.  
    15. Public Function IsAscii(char As String) As Boolean
    16.  
    17.     IsAscii = False
    18.     If InStr(AsciiChars, char) Or char = Chr(34) Or char = Chr(9) Or char = Chr(42) Or char = Chr(13) Or char = Chr(10) Then
    19.        IsAscii = True
    20.     End If
    21.        
    22. End Function
    Last edited by randem; Nov 30th, 2002 at 12:08 PM.

  13. #13

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Hmm...

    Thanks. That'll work... I still can't get it to read rtf colour codes though... Does anyone know how this can be done?

  14. #14
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Originally posted by esmerelda
    Hmm...

    Thanks. That'll work... I still can't get it to read rtf colour codes though... Does anyone know how this can be done?
    You have to set the textrtf to the rtf text.

  15. #15

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    No, I can't get it to work...

  16. #16

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Did this:

    VB Code:
    1. If InStr(1, strData, "CSCMD_PLAY_WATERBG_MID") Then
    2.                                 '
    3.                                 If wmpMusicPlayer.FileName <> "C:\EsMud\music\WATERBG.MID" Then
    4.                                     wmpMusicPlayer.FileName = "C:\EsMud\music\WATERBG.MID"
    5.                                     wmpMusicPlayer.Play
    6.                                 End If
    7.                                 '
    8.                                 'StrTrans (strData)
    9.                                 '
    10.                                 txtGameOutput.Text = txtGameOutput.TextRTF & strData
    11.                                 '
    12.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)
    13.                                 '
    14.                             ElseIf InStr(1, strData, "CSCMD_PLAY_FALINEBG_MID") Then
    15.                                 '
    16.                                 If wmpMusicPlayer.FileName <> "C:\EsMud\music\FALINEBG.MID" Then
    17.                                     wmpMusicPlayer.FileName = "C:\EsMud\music\FALINEBG.MID"
    18.                                     wmpMusicPlayer.Play
    19.                                 End If
    20.                                 '
    21.                                 'StrTrans (strData)
    22.                                 '
    23.                                 txtGameOutput.Text = txtGameOutput.TextRTF & strData
    24.                                 '
    25.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)
    26.                                 '
    27.                             ElseIf InStr(1, strData, "CSCMD_PLAY_SNARL_WAV") Then
    28.                                 '
    29.                                 If wmpSoundPlayer.FileName <> "C:\EsMud\mobprog\SNARL.WAV" Then
    30.                                     wmpSoundPlayer.FileName = "C:\EsMud\mobprog\SNARL.WAV"
    31.                                     wmpSoundPlayer.Play
    32.                                 End If
    33.                                 '
    34.                                 'StrTrans(strData)
    35.                                 '
    36.                                 txtGameOutput.Text = txtGameOutput.TextRTF & strData
    37.                                 '
    38.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)
    39.                                 '
    40.                             ElseIf InStr(1, strData, "CSCMD_STOP_SOUNDS") Then
    41.                                 '
    42.                                 wmpSoundPlayer.Stop
    43.                                 '
    44.                                 'StrTrans(strData)
    45.                                 '
    46.                                 txtGameOutput.Text = txtGameOutput.TextRTF & strData
    47.                                 '
    48.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)
    49.                                 '
    50.                             Else
    51.                                 'If we have received some data, put it into the textbox
    52.                                 'txtGameOutput.Text = txtGameOutput.TextRTF & strData
    53.                                 'Append text without CrLf
    54.                                 'StrTrans(strData)
    55.                                 txtGameOutput.Text = txtGameOutput.TextRTF & strData
    56.                                 'Append text with CrLf
    57.                                 'txtGameOutput.Text = txtGameOutput.TextRTF & strData & vbCrLf
    58.                                 '
    59.                                 'Scroll Down
    60.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)
    61.                                 '
    62.                             End If

    got this

    Code:
    {\rtf1\ansi\deff0{\fonttbl{\f0\froman\fprq2\fcharset0 Courier New;}}
    {\colortbl ;\red255\green255\blue255;}
    \viewkind4\uc1\pard\cf1\lang2057\f0\fs16\{\\rtf1\\ansi\\deff0\{\\fonttbl\{\\f0\\froman\\fprq2\\fcharset0 Courier New;\}\}
    \par \{\\colortbl ;\\red255\\green255\\blue255;\\red0\\green0\\blue128;\}
    \par \\viewkind4\\uc1\\pard\\cf1\\lang2057\\f0\\fs16 
    \par \\par Opening connection to mud.iflipout.com (216.160.238.126) on port 7737...
    \par \\par \\cf2 
    \par \\par \}
    \par \'ff\'fb[\'ff\'fbZ\'ff\'fbV\'ff\'fbU\'ff\'fd\'18
    \par }
    What did I do wrong?

    Oh, also, I want it to remove the CSCMD_ strings when it searches for them. But seeing that the thing whassisname posted above, it's causing me a great deal of headaches...

  17. #17

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Someone suggested this, but I can't figure out how to get it to work...

    VB Code:
    1. If InStr(strData, Chr$(27)) Then
    2.                                 i = InStr(strData, Chr$(27))
    3.                                 While i <> 0
    4.                                     'process
    5.                                     txtGameOutput.SelStart = i + 1
    6.                                     If InStr(i + 1, Text, Chr$(27)) Then
    7.                                         txtGameOutput.SelLength = InStr(i + 1, Chr$(27) - i)
    8.                                     Else
    9.                                         txtGameOutput.SelLength = Len(strData) - i
    10.                                     End If
    11.                                     txtGameOutput.SelColor = Color
    12.                                     etc
    13.                                     txtGameOutput.SelBold = True
    14.                                     etc
    15.                                     txtGameOutput.SelItalic = False
    16.                                     i = InStr(i + 1, strData, Chr$(27))
    17.                                 Wend
    18.                                 txtGameOutput.Text = txtGameOutput.Text & strData
    19.                                 '
    20.                                 txtGameOutput.SelStart = Len(txtGameOutput.Text)

    Where process is the stuff to determine the code and replacement...

    Any ideas?

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