Problems with using INDEX(substr,str) function in Intel Visual Fortran 2011 running on MSVS 2008 Professional

Problems with using INDEX(substr,str) function in Intel Visual Fortran 2011 running on MSVS 2008 Professional

This seems like a simple function to use but I am having problems with the INDEX(substr,str) function returning a zero (0) value even when the substring is within the string.

For example:

Comma delimiter between text input

CHARACTER(LEN=1024) :: STR

STR='ARG1=40,ARG2=2,ARG3=13.5,ARG4=29.6,ARG5=2.9,ARG6=1,*                                             ... ... ...'

LOCC=LEN_TRIM(STR)

LOCD=INDEX(',',STR(1:LOCC)) ! ',' is delimiter for all individual keywords

In the case above, LOCD=0 after the INDEX() statement. I get the same result (LOCD=0) if I use INDEX(',',STR) or if I save ',' to a character variable and use that in the substring argument.

What am I missing here??

IDE information:

Intel(R) Visual Fortran Composer XE 2011 Update 7 Integration for Microsoft Visual Studio* 2008, 12.1.3518.2008, Copyright (C) 2002-2011 Intel Corporation

Intel® C++ Composer XE 2011 Update 10 Integration for Microsoft Visual Studio* 2008, Version 12.1.1111.2008, Copyright© 2002-2012 Intel Corporation

Microsoft Visual C++ 2008

5 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Update: I decided to try the SCAN(STRING,SET,BACK) function in Fortran and this worked perfectly! LOCD is now set to the value of 9, which is the first instance of the character ',' in STR.

INDEX() works just fine in another case where the substring is set to the '*' character. INDEX() also barfed when the substring was set to the '&' character. Is there something about these particular characters that Fortran doesn't like??

I think your use od INDEX had the arguments reversed. You used LOCD=INDEX(',',STR(1:LOCC)) ! ',' whereas the proper use is

result = INDEX (string, substring)

so STR(1:LOCC) should have been first

Usage in Fortran: INDEX(string,substring,...). Did you have the wrong order for the first two arguments?

Hahaha! Yes, thanks. I figured that out since my last post. The reference I was using for INDEX() had the argument order mixed up, showing INDEX(substring,string). If there was a bashful smiley I'd post that here.

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui