Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3036

Re: Using Cases or Position to Find Strings in a List of Strings

From Gregory Lypny <gregory.lypny@videotron.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Using Cases or Position to Find Strings in a List of Strings
Date 2011-06-09 09:45 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <isq4om$642$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hi Patrick,

I was sure I had tried that and it didn't work.  I didn't think StringCases was Listable.  Maybe I did something wrong.

Thanks for the tips,

Gregory


On Tue, Jun 7, 2011, at 4:33 PM, Patrick Scheibe wrote:

> Hi Gregory,
>
> no, you can just *use* StringCases. To find all files here that end
> with .blend you would do:
>
> files = {"~/.blender/9009.blend", "~/.blender/9211.blend",
>  "~/.blender/.bfont.ttf", "~/.blender/.Blanguages",
>  "~/.blender/bpydata", "~/.blender/Bpymenus", "~/.blender/plugins",
>  "~/.blender/quit.blend", "~/.blender/REVISION",
>  "~/.blender/scripts", "~/.blender/VERSION"}
>
> Flatten@StringCases[files, ___ ~~ ".blend" ~~ EndOfString]
>
> and you get
>
> {"~/.blender/9009.blend",
> "~/.blender/9211.blend",
> "~/.blender/quit.blend"}
>
> But maybe I missunderstood your problem. I wouldn't use of course
> StringPosition because if you only want the strings and not the
> positions that it is anyway the wrong function.
>
> Cheers
> Patrick
>
>
> On Tue, 2011-06-07 at 13:10 -0400, Gregory Lypny wrote:
>> Hi Patrick,
>>
>> Yes, I suppose I could map StringCases across the list of strings and then collect all of the results that are not null, but I was hoping it could be done directly with Cases.
>>
>> Thanks,
>>
>> Gregory
>>
>>
>>
>>
>> On Tue, Jun 7, 2011, at 6:51 AM, Patrick Scheibe wrote:
>>
>>> Hi,
>>>
>>> what about using StringCases and StringPosition?
>>>
>>> Cheers
>>> Patrick
>>>
>>> On Tue, 2011-06-07 at 06:48 -0400, Gregory Lypny wrote:
>>>> Hello everyone,
>>>>
>>>> I have a list of strings called myListOfFilePaths and I want to find
>>>> which one of those strings ends in ".DS_Store" (a hidden file created by
>>>> the Mac OS).  I can pick it off using Select as
>>>>
>>>> 	Select[myListOfFilePaths, StringMatchQ[#, ___ ~~ ".DS_Store" ~~
>>>> EndOfString] &]
>>>>
>>>> but I can't do it using Cases or Position
>>>>
>>>> 	Cases[myListOfFilePaths, ___ ~~ ".DS_Store" ~~ EndOfString]
>>>>
>>>> 	Position[myListOfFilePaths, ___ ~~ ".DS_Store" ~~ EndOfString]
>>>>
>>>> despite the fact that Head[___ ~~ ".DS_Store" ~~ EndOfString] is StringExpression.  What am I doing wrong?
>>>>
>>>> 	Regards,
>>>>
>>>> 	Gregory
>>>>
>>>
>>>
>>
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Using Cases or Position to Find Strings in a List of Strings Gregory Lypny <gregory.lypny@videotron.ca> - 2011-06-09 09:45 +0000

csiph-web