|
-
Aug 8th, 2009, 06:56 PM
#1
Thread Starter
Fanatic Member
[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
-
Aug 8th, 2009, 07:17 PM
#2
Re: Remove double String from a String
 Originally Posted by killer7k
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.
-
Aug 8th, 2009, 07:30 PM
#3
Thread Starter
Fanatic Member
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
-
Aug 8th, 2009, 08:07 PM
#4
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
-
Aug 8th, 2009, 08:19 PM
#5
Thread Starter
Fanatic Member
Re: Remove double String from a String
 Originally Posted by Code Doc
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
-
Aug 8th, 2009, 08:21 PM
#6
Thread Starter
Fanatic Member
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
-
Aug 8th, 2009, 08:25 PM
#7
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.
-
Aug 8th, 2009, 08:30 PM
#8
Thread Starter
Fanatic Member
Re: Remove double String from a String
 Originally Posted by Code Doc
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
-
Aug 8th, 2009, 08:38 PM
#9
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.
-
Aug 8th, 2009, 08:39 PM
#10
Thread Starter
Fanatic Member
Re: Remove double String from a String
but i didnt got the answer yet m8
-
Aug 8th, 2009, 10:54 PM
#11
Hyperactive Member
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)
-
Aug 9th, 2009, 05:02 AM
#12
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
-
Aug 9th, 2009, 07:49 AM
#13
Thread Starter
Fanatic Member
Re: Remove double String from a String
 Originally Posted by Billy Conner
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
-
Aug 9th, 2009, 10:08 AM
#14
Hyperactive Member
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:qbe.K=T:qbe.K=T:qbe.K=T: <---Start on this side
if you start from the left hand side the pattern is steve.K=T:qbe.K=T:qbe.K=T:qbe.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.
-
Aug 9th, 2009, 12:10 PM
#15
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|