Results 1 to 8 of 8

Thread: remove using replace function

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    277

    remove using replace function

    hi,

    I wanna remove a line from a textbox and I use the following code

    VB Code:
    1. ln = "e.g Line 3"
    2. Text1 = Replace(Text1, ln, vbnullstring)

    I know it wont work but just to make the idea clear to you

    what should I pass to the replace parameter so that it removes that line completely

    thanks

  2. #2
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Why not use
    VB Code:
    1. text1.text = ""

    ** HOLLY **

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    277
    it wont remove that line

    the multiline property of the textbox is true & if you replace it with "" a blank line will remain there

  4. #4
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    i don't know how to do it using Replace, but i can do it using the Split command

    VB Code:
    1. Dim test As String, remove() As String, line As Integer
    2.    
    3.     test = "remove" & vbCrLf & "the next line!" & vbCrLf & "abcdefghi"
    4.     line = 3 ' -> we want to remove line number 3
    5.  
    6.     remove = Split(test, vbCrLf)
    7.     For i = 0 To UBound(remove)
    8.         If i <> (line - 1) Then ' -> arrays begin with 0, not 1
    9.             Text1.Text = Text1.Text & remove(i) & vbCrLf
    10.         End If
    11.     Next i

    maybe this would be good as a backup if you couldn't find out how with the Replace command
    Anticipation of death is worse than death itself

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    277
    hello Walter

    the problem is that I dont know the line number

    I just know the text of the line I wanna remove

  6. #6
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    oh, i see now! i thought you knew the specific line you wanted to remove. this seems to work for me:

    VB Code:
    1. Dim test As String
    2.     test = "remove" & vbCrLf & "the next line!" & vbCrLf & "abcdefghi"
    3.     test = Replace(test, "abcdefghi", "")
    4.     test = Mid(test, 1, Len(test) - 2)
    5.     Text1.Text = test
    Anticipation of death is worse than death itself

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    277
    oh! it doesn't work

    try this
    VB Code:
    1. Dim test As String
    2. test = "remove" & vbCrLf & "the next line!" & vbCrLf & "abcdefghi"
    3. test = Replace(test, "the next line!", "")
    4. test = Mid(test, 1, Len(test) - 2)
    5. Text1.Text = test

  8. #8
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    i beg your pardon

    you didn't specify whether it was the last line or not. but it works in theory just change it so that it concacenates the rest of the string after it's removed the line
    Anticipation of death is worse than death itself

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