How to filter text in field?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
BIX
Posts: 33
Joined: Fri Oct 27, 2006 2:54 pm

How to filter text in field?

Post by BIX » Sun Jan 14, 2007 2:31 pm

I wanted to filter some text in field and show only files with image extensions.

I've done it this way

Code: Select all

filter field someField with "*jpg"
but it only shows .jpg files.

I want to know is it possible to filter the field with more extensions, like .jpg, .png... I've tried to find it out but i couldn't?
BIX

xApple
Posts: 113
Joined: Wed Nov 29, 2006 10:21 pm
Location: Geneva

Post by xApple » Sun Jan 14, 2007 2:51 pm

The "filter" command can have its limitations...
You seam to be looking for a more complex script...

I've writen something that should do what you want.. tell me what you think about it.

Code: Select all

  set the itemDelimiter to "."
  put "jpg" & return & "jpeg" & return & "png" into myFormatList
  put "1" into x
  repeat
    put last item of line x of field "someField" into myFormatExtension
    put "no" into passTest
    repeat with y = 1 to the number of lines of myFormatList
      if myFormatExtension is line y of myFormatList then put "yes" into passTest
    end repeat
    if passTest is "no" then
      delete line x of field "someField"
    else
      add 1 to x
    end if
    if (x > the number of lines of field "someField") or (field "someField" is empty) then exit repeat
  end repeat
Last edited by xApple on Sun Jan 14, 2007 3:04 pm, edited 1 time in total.

BIX
Posts: 33
Joined: Fri Oct 27, 2006 2:54 pm

Post by BIX » Sun Jan 14, 2007 3:05 pm

it works fine, thanks
BIX

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Location: London, UK
Contact:

Post by Mark Smith » Tue Jan 23, 2007 8:09 pm

This is simpler, and will be a lot faster, if the list of files is very long:

put fld "fileList" into tFList
set the itemDelimiter to "."
repeat for each line L in tFList
if item -1 of L is among the items of "jpg,jpeg,png,gif" then
put L & cr after tFilteredList
end if
end repeat
put char 1 to -2 of tFilteredList into fld "fileList"

best,

Mark

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”