Forums > MaxMSP

How to edit a Text file in MAX?

February 1, 2010 | 4:53 pm

Hi there

I would like to find a way to edit some text files automatically.
For example if I have this text in my text files, I want to extract the number in between "toilets" and "times":

Text file 1:
"Robert has been to the toilets 200 times today"
result: "200"

Text file 2:
"Robert has been to the toilets 22 times today"
result: "22"

Anyone knows how to do that???
Many thanks

Jon


February 1, 2010 | 5:09 pm

Since what you want to do isn’t really well described, I’d suggest that you take a look at the zl object [which would let you group, split, output and concatenate lists] or the route object [which will strip off something you watch for and pass the rest along] or the regexp objects [which will do all kinds of UNIX-style searche/replace operations].

Try looking at those objects as a start….


February 1, 2010 | 5:35 pm

maybe this could help you…

– Pasted Max Patch, click to expand. –

February 1, 2010 | 5:51 pm

Max is probably one of the worst tools for this job, after perhaps MS Paint. Have you thought about using some Javascript?


February 1, 2010 | 6:02 pm

Thanks Gregory.
Sorry for not being too clear…..here is what I’d like to achieve:

I am using a text file generated from an URL page source (myspace page). I am trying to extract a data from this page source which is the number of profile views.
What I want to do is to be able to extract the number that is next to the "profile views" part in the text.

For example, I want to remove everything but the number "26563" below, how do I do that?? :

bgcolor="#ffffff" class="text">

yes it is yes it is yes it is oh yes it is

Leeds/LA/Grenoble/Northampton, London and South East

United Kingdom

Profile Views: 
26563

Last Login: 
01/02/2010


February 1, 2010 | 7:06 pm

this would be my attempt to solve it.
but I still have the feeling that it isn’t the perfect way of doing it.

– Pasted Max Patch, click to expand. –

February 1, 2010 | 7:40 pm

If you’re grabbing the source with [jit.uldl] then try something like this.

lh

– Pasted Max Patch, click to expand. –

February 1, 2010 | 8:51 pm

many thanks I’m nearly there….the code is too long so It doesn’t seem to work…do you wanna have a try?





<br /> ENCHUFADA on MySpace Music – Free Streaming MP3s, Pictures & Music Videos<br />



February 1, 2010 | 9:00 pm

Haha you only needed to post the link! The problem was the spaces between the "Profile Views:" and the actual number is a non-breaking space which in html is


February 1, 2010 | 9:02 pm

thanks mate, yeah it works perfectly now!
Good work!!
Best wishes to all
Jon


February 1, 2010 | 9:20 pm

the [text] object, some zl and some sprintf ist really all you need.


Viewing 11 posts - 1 through 11 (of 11 total)