Replace first X chars in extension

I have this number saved in Database: +664010203

Due to some forwards when I call to this extension in the trace I see this: +6640010203

What I want to do is to remove one zero(0) after +664. Should become +664010203

I can’t use LEN function here because the extensions could be different lengths. So I think the only possibility is to replace +66400 with +664 since this is always like this.

Can someone help me a bit here?

There are several examples of doing this in the sample configuration file. The special case sub-string notation when accessing variables is exactly for this sort of case.

Okay, I’ve made something like this

exten => _+6640010203,1,Set(SAFE_EXTEN=${EXTEN:-6})
same => n,Set(FULL_NUMBER=+664${SAFE_EXTEN})
same => n,Voicemail(${FULL_NUMBER}@VoiceMail)
same => n,Playback(Goodbye)
same => n,Hangup

Not sure if this is optimal way to be done but somehow is works.

But here it is done with direct number e.g. +6640010203 for the test. How can I change this number with extensions from database? I mean to search in database for the extension.

I mean because of the LENGTH I don’t know how long is the extension ( it can be 13, 14 or even 15 numbers ) I can’t do like

exten => _+6640XXXXXXXX,1,Set(COUNT=${ODBC_EXIST(${CALLERID(num)})})

The above example is for numbers with 13 numbers. What about 14 or 15? Do I need to do same as above for each length?