I'm trying to cut some strings which contains the symbol '_' using STRMATCH and STRSPLIT, in order to modify them, in this way:
mystring=['aaa_111','bbb_222','ccc','ddd']
nmax=N_ELEMENTS(mystring)
cut_mystring=STRARR(2,nmax)
FOR i=0, nmax-1 DO BEGIN
IF (STRMATCH(mystring[i], '*_*') eq 1) THEN BEGIN
cut_mystring[i]=STRSPLIT(mystring[i], '_', /EXTRACT)
mystring_new[i]= cut_mystring[0,i]+'_MYCOMMENT_'+cut_mystring[1,i]
ENDIF
ENDFOR
print, mystring_new[i]
The result of print, mystring_new[i] is:
aaa_111
222_MYCOMMENT_
ccc
ddd
So, it seems to work for the first element (and of course for the last two, too), but not for the second.
What am I doing wrong here? Thanks!