delete the last char of a string

Dalmazzo's icon

Hi All,
I'm searching for a method to delete the last char of a string. I'm trying with regexp but don't find the good solution.
If i use regexp .{9} for example it works but if the number go smaller it brakes the string output.
The idea is that someone type his email on a virtual keyboard, the keys are ade of just message mutton with characters and they add a char on a string but don't know how to delete the last char added.
Thanks for the help

hz37's icon

I had a similar need a while back. This is what I did:

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

Source Audio's icon
Max Patch
Copy patch and select New From Clipboard in Max.
metamax's icon
Max Patch
Copy patch and select New From Clipboard in Max.

mp's icon

Sorry for the irruption…

A 'similar' question (deleting chars from a string) didn't get answer and I'm not so good with regexp…

example:
input: midi_symbol
needed output: midi_symbol (unchanged)

input: midi_midi_symbol
needed output: midi_symbol

my solution:

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

Is there maybe a more elegant/efficient function than mine?

Many thanks for any help.

matteo

metamax's icon

matteo, your solution looks good. Also note that _midi (with a leading underscore) is unique to midi_midi_symbol. You can just remove it from any input.

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

mp's icon

Thank you metamax

Christopher Dobrian's icon

In the js object, JavaScript provides string operation methods that are handy for such tasks. For example,

function anything(input) {
    outlet(0, messagename.slice(0,messagename.length-1));
}

This will output the message selector (the first word in the incoming message) without its last character. Note that if you send in a list, int, or float, the message selector will be list, msg_int, or msg_float, so the output will be lis, msg_in, or msg_floa, and if you send in a multi-word message all but the first word will be ignored. You can get around that, if you want, by putting a tosymbol object before the js object.

Here (attached) is an example JavaScript file, and (below) a test patch.

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

deletelastcharacter.js
js
Dalmazzo's icon

thanks a lot for the solutions, regexp option is perfect. Thanks!

johan Brøndum de Reybekill's icon

Thats so helpfull.
I went with Source Audio's solution.
Thank you.