- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Usage in Fortran: INDEX(string,substring,...). Did you have the wrong order for the first two arguments?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page