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

How to Add NULL Character to End of CHAR Variable

jkrob
초급자
4,908 조회수
All,

My routine is doing a formatted read of a character string from a file to the character variable CFOO and I need to add a NULL character to the end of that character string within CFOO. How is that done?

Thanks in advance,
Jeff
0 포인트
2 응답
anthonyrichards
새로운 기여자 III
4,908 조회수

you can generate the NULL character using the function CHAR with zero argument i.e. nullchar=CHAR(0). Add it using the stringconcatenate operator '//' thus

string=TRIM(ADJUSTL(string))//char(0)

ADJUSTL moves the characters in 'string' to the left of the space allotted for the string, removing leading blanks and adding trailing blanks on the right.TRIM chops off all trailing blank characters.You then add theh NULL to the end of the TRImmed result and store the result back into 'string' (or another string). If you know the length of 'string' excluding trailing blanks, you could use

string=string(1:length)//CHAR(0)

This works so long as the space assigned to character string 'string' is at least 1 character longer than 'length'.

0 포인트
jkrob
초급자
4,908 조회수
Thanks!!! That was it!

Jeff
0 포인트
응답