Results 1 to 4 of 4

Thread: Removing something inbetween two strings

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Removing something inbetween two strings

    Okay, say text box1 is like this:
    Code:
    Create Animated Emoticons in Your Chats! Get MSN Messenger.
    			
    Audi S4
    View Pictures, Specs & Detailed Info about the 2005 Audi S4
    			
    Find a Birth Month & Year
    Over 100 Million Birthdays Search by Name. Free Search.
    			
    Clan/Guild Skins
    Custom and pre-made skins available with an easy to use portal design
    (an example)
    and lets say i wanted to replace everything except these two parts...without splitting by vbcrlf:
    Code:
    Create Animated Emoticons in Your Chats! Get MSN Messenger.
    
    Audi S4
    View Pictures, Specs & Detailed Info about the 2005 Audi S4
    i know its mid, but how do i find the letters number?example would be nice

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Removing something inbetween two strings

    Mid$ with InStr :

    VB Code:
    1. Dim iPos As Integer
    2.    
    3.     iPos = InStr(1, Text1.Text, "Find a Birth Month & Year")
    4.    
    5.     MsgBox Mid$(Text1.Text, 1, iPos - 1)


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Removing something inbetween two strings

    This function removes everything from OriginalString between String1 & String2

    VB Code:
    1. Function RemoveX(ByVal OriginalString As String, ByVal String1 As String, String2 As String) As String
    2.     Dim i As Long, j As Long
    3.     i = InStr(OriginalString, String1) + Len(String1)
    4.     RemoveX = Left(OriginalString, i)
    5.     i = InStr(i, OriginalString, String2)
    6.     RemoveX = RemoveX & Mid(OriginalString, i)
    7. End Function
    8.  
    9. Private Sub Command2_Click()
    10.     ''Use it like this
    11.     MsgBox RemoveX("That was a very good example", "was", "good")
    12. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Addicted Member prophecy's Avatar
    Join Date
    Mar 2005
    Location
    In the developers list of Visual Basic ;-)
    Posts
    242

    Re: Removing something inbetween two strings

    well.. if u knw wat the exact string is u can also use replace function like...

    Replace("That was a very good example","That was","")

    it replaces it with a blank string.. equivalent to removing it

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