Search for control character

Search for control character

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

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.


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).



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.


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?


Leave a Comment

Please sign in to add a comment. Not a member? Join today