Results 1 to 5 of 5

Thread: about Replace$

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    about Replace$

    suppose i have a text file in which its words should be separated by one space only, and i don't want some one to cheat by inserting other spaces, i know there is a regular expression solution for such cases, but i prefer a ready to use functions
    this is my approach using a string instead of a file, it seems to work, other solutions is appreciated.
    also why the text in the TextBox selected ?
    Uses "UI"
     
      Begin ControlID
        %ID_TextBox2
         
      End ControlID
         
      Function TBMain()  
        Dim hDlg, i As Long 
        Dim stringo As String
        stringo = "Goto          (goto , GOTO                    , GO TO or other case       combinations, depending on    the programming language) is a    statement found in many computer        programming languages. It performs a one-way transfer   of control to another line of code" 
        For i=1 To 100
        stringo = Replace$(stringo, "  ", " ")
        If InStr(1, Stringo, "  ") = 0 Then
        Exit For
        End If
        Next
        'msgbox 0, str$(i)
        Dialog New 0, "replace many spaces to one space", -1, -1, 500, 400, _
                                                      %WS_DLGFRAME Or %DS_CENTER Or %WS_CAPTION Or %WS_SYSMENU, _
                                                      0 To hDlg
     
        
        Control Add Textbox , hDlg, %ID_TextBox2, "test" , 5,  25, 450, 310,  %ES_WANTRETURN  Or _
                                                                              %ES_MULTILINE   Or _
                                                                              %ES_AUTOVSCROLL Or _ 
                                                                                            
         
    Control Append Text hDlg, %ID_TextBox2, $CRLF & stringo & $CRLF     
     
        '---Show dialog in MODAL
        Dialog Show Modal hDlg, Call dlgCallback
      End Function
       
      CallBack Function dlgCallback() As Long
       
        Select Case CBMSG
          Case %WM_CLOSE
        End Select 
       
      End Function
    
    EDIT:
    this is a better solution:
    replace:
    For i=1 To 100
        stringo = Replace$(stringo, "  ", " ")
        If InStr(1, Stringo, "  ") = 0 Then
        Exit For
        End If
        Next
    
    with:
    Repeat
        stringo = Replace$(stringo, "  ", " ")
        Until InStr(1, Stringo, "  ") = 0
    
    Last edited by primo; 23-12-2016 at 08:48.

Similar Threads

  1. file and replace qt :)
    By lydia_sp in forum File
    Replies: 7
    Last Post: 15-09-2009, 18:28

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •