Results 1 to 15 of 15

Thread: [RESOLVED] Remove double String from a String

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Resolved [RESOLVED] Remove double String from a String

    Hi ,

    i'am trying to remove double String from
    like in this example

    Code:
    steve.K=T:qbe.K=T:qbe.K=T:qbe.K=T:
    987654321_qn�K.X1_qn�K.X1_qn�K.X1_
    i'am trying to get in the first string steve and in the second string 987654321

    i dont know how to compare or something to extract that

    Thanks

  2. #2
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Remove double String from a String

    Quote Originally Posted by killer7k View Post
    Hi,
    I'm trying to remove the double string from this example:

    Code:
    steve.K=T:qbe.K=T:qbe.K=T:qbe.K=T:
    987654321_qn�K.X1_qn�K.X1_qn�K.X1_
    I am trying to get in the first string, steve and in the second string 987654321. I don't know how to compare or something to extract that.

    Thanks
    Any idea what is inside the square boxes? That could be rather important before code is written to solve the problem. Also, if I did not translate your question correctly, please advise.
    Doctor Ed

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    Yes thanks i cant explain it well
    i only got the same result posted there
    i wanna get ride of those string after the original string
    feel free to understand it on your way

    wanna extract from the first string is gonna be unique always come on the first string and remove other duplicated

    Thanks

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Remove double String from a String

    This does it. Add a command button to a form and then click on it after adding this code:
    Code:
    Private Sub Command1_Click()
    Dim Str1 As String, Str2 As String
    Str1 = "steve.K=T:qbe.K=T:qbe.K=T:qbe.K=T:"
    Str2 = "987654321_qn?K.X1_qn?K.X1_qn?K.X1_"
    Str1 = Left$(Str1, InStr(Str1, ".") - 1)
    Str2 = Left$(Str2, InStr(Str2, "_") - 1)
    MsgBox Str1 & vbCrLf & Str2
    End Sub
    Doctor Ed

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    Quote Originally Posted by Code Doc View Post
    This does it. Add a command button to a form and then click on it after adding this code:
    Code:
    Private Sub Command1_Click()
    Dim Str1 As String, Str2 As String
    Str1 = "steve.K=T:qbe.K=T:qbe.K=T:qbe.K=T:"
    Str2 = "987654321_qn?K.X1_qn?K.X1_qn?K.X1_"
    Str1 = Left$(Str1, InStr(Str1, ".") - 1)
    Str2 = Left$(Str2, InStr(Str2, "_") - 1)
    MsgBox Str1 & vbCrLf & Str2
    End Sub
    hmm Thanks ,
    but i think you didnt understand me good cause i cant use only . or _ everytime i can have different string so i should make it dynamic
    here you other example

    Code:
    brad123]slI,Z3]slI,Z3]slI,Z3] 
    12345~mj!D2[5~mj!D2[5~mj!D2[5~mj
    steve.K=T:qbe.K=T:qbe.K=T:qbe.K=T:
    987654321_qn�K.X1_qn�K.X1_qn�K.X1_
    
    must be like 
    brad123
    12345
    steve
    987654321
    Thanks cause i really tried to get an algo for that but i couldnt get it

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    oh i wanna just added that in each string some string double each other i think is the way to get ride off

    Thanks

  7. #7
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Remove double String from a String

    If the delimiter character changes continuously from one string to the next, then you are a dead duck because there is no consistency.
    Doctor Ed

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    Quote Originally Posted by Code Doc View Post
    If the delimiter character changes continuously from one string to the next, then you are a dead duck because there is no consistency.
    yes but i was studying the output and found that the other string that i wanna remove come as double are same
    look in this example
    Code:
    brad123]slI,Z3]slI,Z3]slI,Z3]
    Now the true string is : brad123
    next it come a serie of 3 doube of string ]slI,Z3]..

    brad123]slI,Z3]slI,Z3]slI,Z3]
    1 2 3
    as you see the double are the same

    brad123 ]slI,Z3 ]slI,Z3 ]slI,Z3]
    'true str 1 double 2 double 3 double


    what do you think ?

    Thanks

  9. #9
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Remove double String from a String

    Killer7k said, "what do you think?"
    -------------
    I think that you should mark your thread Resolved using the thread tools.
    Doctor Ed

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    but i didnt got the answer yet m8

  11. #11
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: Remove double String from a String

    well i worked on it a bit. my instinct tells me i need to work from the right side of the string to the left to get true results but i haven't gotten it to work that way. this code here doesn't follow that pattern but it seems to work so far. from the way it's made i don't really see it being faultless, but you can check it out to see how it works out for you.
    Code:
    Private Function RemoveExtra(pStr As String) As String
    
        Dim Pos As Long, Cnt As Long, pLen As Long
        Dim Data() As String, mStr As String
        
        Pos = 1
        pLen = 4
        Cnt = 0
        Do Until Pos = Len(pStr)
            mStr = Mid$(pStr, Pos, pLen)
            Data() = Split(pStr, mStr)
            If UBound(Data) >= 3 Then
                Cnt = Cnt + 1
                pLen = pLen + 1
            Else
                If Cnt Then
                    RemoveExtra = Left$(pStr, InStr(pStr, mStr))
                    Exit Do
                Else
                    Pos = Pos + 1
                End If
            End If
        Loop
        
    End Function
    edit: to call it just do something like MyRetStr = RemoveExtra(FullStr)

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Remove double String from a String

    I think it is possible, if my weird logic stands

    Let me give it a try. But before I do I have couple of questions. If you find them funny, still answer them if you want me to help you...

    1) What will be the minimum length of the "True" String in any given condition?
    2) What will be the minimum and maximum length of the "Duplicate" String in any given condition?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Remove double String from a String

    Quote Originally Posted by Billy Conner View Post
    well i worked on it a bit. my instinct tells me i need to work from the right side of the string to the left to get true results but i haven't gotten it to work that way. this code here doesn't follow that pattern but it seems to work so far. from the way it's made i don't really see it being faultless, but you can check it out to see how it works out for you.
    Code:
    Private Function RemoveExtra(pStr As String) As String
    
        Dim Pos As Long, Cnt As Long, pLen As Long
        Dim Data() As String, mStr As String
        
        Pos = 1
        pLen = 4
        Cnt = 0
        Do Until Pos = Len(pStr)
            mStr = Mid$(pStr, Pos, pLen)
            Data() = Split(pStr, mStr)
            If UBound(Data) >= 3 Then
                Cnt = Cnt + 1
                pLen = pLen + 1
            Else
                If Cnt Then
                    RemoveExtra = Left$(pStr, InStr(pStr, mStr))
                    Exit Do
                Else
                    Pos = Pos + 1
                End If
            End If
        Loop
        
    End Function
    edit: to call it just do something like MyRetStr = RemoveExtra(FullStr)
    Thanks m8 your function work really good
    it helped me a lot of and got my life easier with that

    @koolsid,
    Thanks m8 but seem Billy Conner function working good

    Thanks again and cheerz

  14. #14
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Exclamation Re: [RESOLVED] Remove double String from a String

    i know its resolved but i'd like to expand on this further.
    the problem with your pattern is that the last character of what you want to keep is always part of the pattern..(unless this is how it was meant to be designed)
    for example..
    (underlined and italic are the full pattern. bold is the partial pattern)
    if you start from the right hand side the pattern is steve.K=T:qb e.K=T:qb e.K=T:qb e.K=T: <---Start on this side
    if you start from the left hand side the pattern is steve.K=T:qb e.K=T:qb e.K=T:qb e.K=T:
    basically the same each way you look at it. the reason i start with the "e" on the left side is because if i make a program to look for the best matches the computer will find that as the starting point is its part of the pattern.

    if you notice, your pattern on each of your examples starts with the last letter of what you want to return. in this case its the e in steve, so in my function i had to leave the first letter in of the pattern in my example to make it work.
    that is the reason i don't believe this will work flawlessly is because i have not examined all possible outcomes that you could come by in whatever data your inputting from. the data your inputting (in theory) could use more of the pattern in what you wish to return than just one character. in that case you could end up with a lot less data returning than whats really wanted. so i suggest you do more research on the data input to make sure this doesn't happen.
    but anyway, i cannot think of a better solution for this currently. if one magically pops in my head sometime i'll post it in here for you.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: [RESOLVED] Remove double String from a String

    Thanks m8 really appreciated
    for now it work really good if somedays i got a string as different output i will try to see what we can do

    Thanks & cheerz

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