cut a symbol after n characters

Roman Thilenius's icon

how do i cut a symbol after n characters (so that for example words end after 10 characters) while avoiding to split it into a list of characters?

Christopher Dobrian's icon

JavaScript has methods slice() and substr() for obtaining a part of a string.

function anything()
{
    outlet(0,messagename.slice(0,10));
}

pdelges's icon

Roman, what's wrong with lists of char?

Another way is to use regexp .{10} like this:

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

it is for something which is uzi´ed ... i want to write 20-30 files to disk at once. and actually i dont find a good way to get it into a list of characters either. i mostly use OS9 so i dont know much about java or regexp ... but this is for a Max 6 project, so i will probably use regexp.
thanks for your examples - but feel free to add more.

(karrrlo)'s icon

[jit.str.msymbol] could be of some help, might need some specific formating as you may notice in the example :

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

looks cool, but i dont fully get it.

why is "jit.matrix 1 char 10 1" also removing the 3th , the 5th and the 8th character in addition to limiting the whole thing to 10?

(karrrlo)'s icon
Max Patch
Copy patch and select New From Clipboard in Max.

Due to lack of time it was a quick response pointing to one direction. that is why i mentioned it needed some formating. i actually did a mistake putting in the jit.matrix between the two jit.str objects which created the unexpected behaviours you mentioned.
here is a better solution still in the jit.str "paradigm".
Notice that spaces are counted as characters.

(karrrlo)'s icon

Also jasch's [strcut] external does exactly what you need.
from its help file :
"terminate string at position - arguments: position (int) default 0, mode (0/1) default 0"

Fora's icon

I'm pretty late to the party but I've built an abstraction awhile back that you may find useful.

f_split.zip
zip
Mark Durham's icon

Not too late for me... thanks Fora.

Fora's icon

You're welcome! ;)

James Gatenby's icon

Still useful Fora!