Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Search for control character

blbaker
Beginner
454 Views
How can I search for a nonprintable control character? Index does not seem to work with CR or LF characters! See code ex: cr = " "
crlf = " "
bline = TRIM(bline) // crlf(1:2)
iloc = index(bline, cr)
iloc aways returns zero. Whats the trick here? Thanks Bruce
0 Kudos
4 Replies
nijhuis
Beginner
454 Views
I tried your statements and on my system it worked correct.
Is bline long enough to hold the extra 2 characters.
bline must contain in your example at least two spaces at the end to work correct. If so, does bline contain a non-printable character at the end, for example a zero value?
This can be checked in the watch window in debug mode by entering bline,x to see the hexadecimal presentation of bline.

Guus
0 Kudos
llynisa
Beginner
454 Views
and are escape sequences in null-terminated C strings, not Fortran control characters, which are CR = CHAR(13) & LF = CHAR(10).

Having said that, there is nothing wrong with your scrap of code, which works for me, and would when modifed also work for finding CHAR(10) & CHAR(13).

HTH

Alan
0 Kudos
Jugoslav_Dujic
Valued Contributor II
454 Views
It seems that you added too much C spice ;-):
cr = char(13)
crlf = char(13)//char(10)
bline = TRIM(bline) // crlf(1:2) 
iloc = index(bline, cr)

Is it better now?

Jugoslav
0 Kudos
llynisa
Beginner
454 Views
Another point that occurs to me is that if bline is a null-terminated C-string, one can have all sorts of characters beyond the null that will not be removed by TRIM, hence your crlf(1:2) may not find room to be included in bline.

It's simpler in Fortran.

Alan


0 Kudos
Reply