Forums > MaxMSP

substituting with a backslash in a regexp

April 22, 2008 | 3:44 am

could someone please enlighten me as to why the following does not replace all spaces with a backslash and a space ( ) ?

regexp @re " " @substitute "\ "

I’m trying to substitute all spaces in a file path with a backslash and a space so the path works with a "read" command in a pattrstorage to read the path to my preset xml file… otherwise the path truncates at a space in the path.

from reading the help file it says that two backslashes should give you a in your regex.

thanks for any help you might be able to offer…


April 22, 2008 | 7:12 am

On 22 avr. 08, at 05:44, ed guild wrote:

> could someone please enlighten me as to why the following does not
> replace all spaces with a backslash and a space ( ) ?
>
> regexp @re " " @substitute "\ "
>
> I’m trying to substitute all spaces in a file path with a backslash
> and a space so the path works with a "read" command in a
> pattrstorage to read the path to my preset xml file… otherwise the
> path truncates at a space in the path.

You shouldn’t be using regexp for that. The real source of the problem
is that you have spaces in your path, so just deal with that. You may
have a look to [tosymbol] object, which allows you to make a symbol,
or maybe [sprintf] with the symout argument. Anyway, if you provide an
example of what you’re doing, you’ll get a more precise answer.

ej


April 23, 2008 | 6:07 am

ed guild schrieb:
> I’m trying to substitute all spaces in a file path with a backslash
> and a space so the path works with a "read" command in a pattrstorage
> to read the path to my preset xml file… otherwise the path
> truncates at a space in the path.

It wouldn’t work anyway, and if you use a [tosymbol] with your "path
with spaces" any reading max object will happily take it as a complete
path and now what you want to load…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


April 23, 2008 | 12:58 pm

thank you both for pointing me to the "tosymout" option. I wasn’t aware of that.

this worked perfectly.

what I am doing is making a sub-patch that will take an input folder path (path to the main patch in my case) and then I’m using sprintf to add on a sub-folder and a file name.

this path to file name is used as the "read" and "write" file for a pattrstorage XML file.

I was having trouble reading from an included XML file when building my patch as a Mac OS X application.

So I figured if I kept my preset xml files in a "prefs" folder next to my patch/application, I could work around that issue.

here is the patch if you are interested in seeing my result.

thanks again for the help!
/ed

#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 151 150 125 196617 set location and preset .xml file name here;
#P window linecount 1;
#P newex 486 190 62 196617 prepend set;
#P newex 378 89 65 196617 select Store;
#P newex 486 170 73 196617 prepend write;
#P newex 488 148 252 196617 sprintf symout %sprefs/pref_drumlab_drummap.xml;
#P newex 379 110 30 196617 t b b;
#P window linecount 2;
#P message 387 255 305 196617 write "zardoz:/Users/vizzie/Documents/VizPatches/Development/DrumLab 1.5/prefs/pref_drumlab_drummap.xml";
#P window linecount 1;
#P message 400 154 43 196617 store 1;
#P newex 28 181 57 196617 unpack 1 s;
#P newex 27 157 42 196617 pak 1 s;
#P newex 49 52 79 196617 print patchRoot;
#P newex 28 78 52 196617 toSymbol;
#P newex 40 365 62 196617 prepend set;
#P newex 74 204 68 196617 prepend read;
#P newex 28 130 252 196617 sprintf symout %sprefs/pref_drumlab_drummap.xml;
#P window linecount 2;
#P message 40 386 305 196617 read "zardoz:/Users/vizzie/Documents/VizPatches/Development/DrumLab 1.5/prefs/pref_drumlab_drummap.xml";
#N comlet messages to pattrstorage;
#P outlet 28 328 15 0;
#N comlet input Store (message);
#P inlet 378 53 15 0;
#N comlet input patchRoot (text);
#P inlet 28 53 15 0;
#P window linecount 6;
#P comment 517 42 234 196617 loadPrefs: communicates with pattrstorage object requires a file path (generally the root path to the main patch file or application) a "Store" message will trigger a save to slot 1 and write the presets to the .xml preset file YOU NEED TO MANUALLY SET THE FILE NAME IN TWO PLACES BELOW;
#P window linecount 2;
#P comment 351 385 100 196617 this is here for debugging purposes;
#P comment 603 167 125 196617 set location and preset .xml file name here;
#P comment 396 53 100 196617 "Store" msg to write to prefs file;
#P window linecount 3;
#P comment 135 54 100 196617 root path for location to save preferences;
#P connect 12 0 9 0;
#P connect 12 0 19 0;
#P connect 20 0 22 0;
#P connect 19 0 20 0;
#P connect 18 1 16 0;
#P connect 22 0 17 0;
#P connect 18 0 17 0;
#P connect 21 0 18 0;
#P connect 6 0 21 0;
#P connect 15 1 10 0;
#P connect 9 0 14 1;
#P connect 5 0 12 0;
#P connect 5 0 13 0;
#P connect 11 0 8 0;
#P connect 10 0 11 0;
#P connect 10 0 7 0;
#P connect 16 0 7 0;
#P connect 17 0 7 0;
#P connect 15 0 7 0;
#P connect 14 0 15 0;
#P window clipboard copycount 24;


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