Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 how i can filter my strings
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sadra
Starting Member

Iran
30 Posts

Posted - 07 December 2008 :  03:02:45  Show Profile  Send sadra a Yahoo! Message  Reply with Quote
Hi, to all
please help...

I have 2 string(myString1 & myString2) and i want filter the myString2 from myString1

myString1 = txt1, txt2, txt3, txt4
myString2 = txt1, txt2

myString3 = txt3, txt4

how i can filter myString2 from myString1 and i get myString3?<

[red]how soon is too late[/red]

AnonJr
Moderator

United States
5768 Posts

Posted - 07 December 2008 :  08:57:07  Show Profile  Visit AnonJr's Homepage  Reply with Quote
Ask over at http://stackoverflow.com ?

While we do occasionally foray into general programming (and some non-programming) topics, we tend to be a little more tightly focused. You may get a faster result by going to a general programming Q&A site like stackoverflow.com<
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 07 December 2008 :  11:00:26  Show Profile  Reply with Quote
there are probably many ways to do this. I had some time on my hands and wrote this.
It looks complicated but its not and it may not be what you want, if not, someone may find it useful.

<%

Dim myString1
Dim myString2
Dim txt1, txt2, txt3, txt4
dim FilteredStr

txt1 = "Bob"
txt2 = "Carol"
txt3 = "Ted"
txt4 = "Alice"

myString1 = txt1 & "," & txt2 & "," & txt3 & "," &  txt4
myString2 = txt1 & "," & txt2

FilteredStr = ReturnFilteredStr(myString1,myString2)  'function returns new filtered string

WriteFilteredStr FilteredStr       'sub to write the new string to page

Function ReturnFilteredStr(str1,str2)
    Dim strToFilter
    Dim strWhatToFilter
    Dim strFiltered
    Dim objRegex
    Dim iCnt
    Dim iCnt2
    Dim fStr

    strToFilter = split(str1,",")       'myString1 split at comma
    strWhatToFilter = split(str2,",")   'myString2 split at comma
    strFiltered = ""                    'variable to hold strings that make it through the filter

    Set objRegex = New Regexp           'Set new regular expression to handle match and replace duties
    objRegex.ignorecase = true
    objRegex.global = true

    for iCnt = 0 to uBound(strToFilter) 'Loop through myString1
        fStr = trim(strtoFilter(iCnt))  'String to Match


        for iCnt2 = 0 to uBound(strWhatToFilter)    '2nd loop to cycle through myString2
            fStr2 = trim(strToFilter(iCnt2))        'String pattern

            objRegex.Pattern = fStr2
            fStr = objRegex.Replace(fStr,"")        'If String to Match = String pattern then String to match is replaced with ""
        next

        if fStr <> "" then
            if strFiltered <> "" then
                strFiltered = strFiltered & "," & fStr   'if string to Match made it through the filter its added to the new string
            else
                strFiltered = fStr
            end if
        end if
    next

    Set objRegex = Nothing                       'object clean up

    ReturnFilteredStr = strFiltered
End Function 

Sub WriteFilteredStr(str)
    Dim strArr
    Dim iCnt

    if str <> "" then
        strArr = split(str,",")
        for iCnt = 0 to uBound(strArr)
            Response.Write strArr(iCnt) & "<br />"
        next
    else
        Response.Write "Your filtered string is empty."
    end if
End Sub

%>

<

    _-/Cripto9t\-_

Edited by - cripto9t on 07 December 2008 17:06:00
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 08 December 2008 :  10:06:07  Show Profile  Reply with Quote
Here, this is a bit easier:


inta=len(MyString2)
for ia=1 to (len(MyString1)-inta)
	if mid(MyString1,ia,inta)=MyString2 then
		MyString3=left(MyString1,ia-1)&mid(MyString1,ia+inta)
	end if
next
<

Edited by - Carefree on 08 December 2008 10:06:41
Go to Top of Page

sadra
Starting Member

Iran
30 Posts

Posted - 09 December 2008 :  22:52:13  Show Profile  Send sadra a Yahoo! Message  Reply with Quote
quote:
Originally posted by AnonJr

Ask over at http://stackoverflow.com ?

While we do occasionally foray into general programming (and some non-programming) topics, we tend to be a little more tightly focused. You may get a faster result by going to a general programming Q&A site like stackoverflow.com



Ok!<

[red]how soon is too late[/red]
Go to Top of Page

sadra
Starting Member

Iran
30 Posts

Posted - 09 December 2008 :  22:53:21  Show Profile  Send sadra a Yahoo! Message  Reply with Quote
quote:
Originally posted by cripto9t

there are probably many ways to do this. I had some time on my hands and wrote this.
It looks complicated but its not and it may not be what you want, if not, someone may find it useful.

<%

Dim myString1
Dim myString2
Dim txt1, txt2, txt3, txt4
dim FilteredStr

txt1 = "Bob"
txt2 = "Carol"
txt3 = "Ted"
txt4 = "Alice"

myString1 = txt1 & "," & txt2 & "," & txt3 & "," &  txt4
myString2 = txt1 & "," & txt2

FilteredStr = ReturnFilteredStr(myString1,myString2)  'function returns new filtered string

WriteFilteredStr FilteredStr       'sub to write the new string to page

Function ReturnFilteredStr(str1,str2)
    Dim strToFilter
    Dim strWhatToFilter
    Dim strFiltered
    Dim objRegex
    Dim iCnt
    Dim iCnt2
    Dim fStr

    strToFilter = split(str1,",")       'myString1 split at comma
    strWhatToFilter = split(str2,",")   'myString2 split at comma
    strFiltered = ""                    'variable to hold strings that make it through the filter

    Set objRegex = New Regexp           'Set new regular expression to handle match and replace duties
    objRegex.ignorecase = true
    objRegex.global = true

    for iCnt = 0 to uBound(strToFilter) 'Loop through myString1
        fStr = trim(strtoFilter(iCnt))  'String to Match


        for iCnt2 = 0 to uBound(strWhatToFilter)    '2nd loop to cycle through myString2
            fStr2 = trim(strToFilter(iCnt2))        'String pattern

            objRegex.Pattern = fStr2
            fStr = objRegex.Replace(fStr,"")        'If String to Match = String pattern then String to match is replaced with ""
        next

        if fStr <> "" then
            if strFiltered <> "" then
                strFiltered = strFiltered & "," & fStr   'if string to Match made it through the filter its added to the new string
            else
                strFiltered = fStr
            end if
        end if
    next

    Set objRegex = Nothing                       'object clean up

    ReturnFilteredStr = strFiltered
End Function 

Sub WriteFilteredStr(str)
    Dim strArr
    Dim iCnt

    if str <> "" then
        strArr = split(str,",")
        for iCnt = 0 to uBound(strArr)
            Response.Write strArr(iCnt) & "<br />"
        next
    else
        Response.Write "Your filtered string is empty."
    end if
End Sub

%>






Tanx Mr cripto9t
Best Regards<

[red]how soon is too late[/red]
Go to Top of Page

sadra
Starting Member

Iran
30 Posts

Posted - 09 December 2008 :  22:57:26  Show Profile  Send sadra a Yahoo! Message  Reply with Quote
quote:
Originally posted by Carefree

Here, this is a bit easier:


inta=len(MyString2)
for ia=1 to (len(MyString1)-inta)
	if mid(MyString1,ia,inta)=MyString2 then
		MyString3=left(MyString1,ia-1)&mid(MyString1,ia+inta)
	end if
next




Tanx Mr Carefree
Best Regards<

[red]how soon is too late[/red]
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 09 December 2008 :  23:46:43  Show Profile  Reply with Quote
You're welcome. Feel free to ask questions any time.<
Go to Top of Page

Etymon
Advanced Member

United States
2385 Posts

Posted - 09 December 2008 :  23:55:32  Show Profile  Visit Etymon's Homepage  Reply with Quote
Mr. Carefree ... that kind of has a cool ring to it! <

Edited by - Etymon on 09 December 2008 23:56:10
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 10 December 2008 :  09:07:46  Show Profile  Visit AnonJr's Homepage  Reply with Quote
quote:
Originally posted by Etymon

Mr. Carefree ... that kind of has a cool ring to it!

Kinda like "Mr. Feel Good"? <
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 10 December 2008 :  13:07:56  Show Profile  Reply with Quote
Should have had a career in Reggae?<
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000 Version 3.4.07