Results 1 to 8 of 8

Thread: RIchTextBox How To Eliminate All Non_ascii chars

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    RIchTextBox How To Eliminate All Non_ascii chars

    hi guys...

    i was wodering how to make a button that when clicked would recognize all non ascii chars and if found any non asci to remove them and put "space" instead...


    i need that because when i send data to weserver i encode the data and i even if i dont encode it the data gets encoded and sent..but if some strange chars get inside the data im sending my data is not sent!
    Thanks for helping me out.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    AFAIK, ascii characters can be from 0 to 255, could you cite a non-ascii character?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    sure... sec
    I dont k now if this is ascii but :
    The char is fro mcharacter map : U+2013 En and it is like a "-"char but double the size...

    and when i copy that char into my textfield it's ok..but then when i send it over the net the data does not come... if i remove that the data is sent regularly...hmmm
    Thanks for helping me out.

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    You mean you can copy it to a textbox? If yes then you can get its ascii value using ASC.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    Lively Member TechNix's Avatar
    Join Date
    Nov 2008
    Location
    Manila
    Posts
    69

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    The character you are pertaining is an "En Dash" like this "–"?
    or an "Em Dash" which is longer than the "En Dash"?
    the Ascii value for an En Dash is 150 while the Em Dash is 151.
    Anyways, assuming its an Em Dash, the following code will replace all the Em Dash to Space in the RTB control:
    Code:
    Private Sub Command1_Click()
    RichTextBox1.Text = RemoveEmDash(RichTextBox1.Text)
    End Sub
    
    Function RemoveEmDash(str As String) As String
    RemoveInvalid = Replace(str, Chr$(151), " ")
    End Function

  6. #6
    Lively Member TechNix's Avatar
    Join Date
    Nov 2008
    Location
    Manila
    Posts
    69

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    I have over read the code, my mistake. Function RemoveEmDash should be like this:
    Code:
    Function RemoveEmDash(str As String) As String
    RemoveEmDash = Replace(str, Chr$(151), " ")
    End Function

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    Try this that I didn't test:
    Code:
        Dim bt() As Byte, i As Long
    
        bt = RichTextBox1.Text
        For i = 1 To UBound(bt) Step 2
            If bt(i) > 0 Then
                bt(i - 1) = 32
                bt(i) = 0
            End If
        Next
        RichTextBox1.Text = bt
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: RIchTextBox How To Eliminate All Non_ascii chars

    ok guys..will try it today...
    Thanks for helping me out.

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