CHARACTER: specify and initialize the character string data type
⇒Help
⇒Contents
⇒Strings
(⇒Optional Keywords Syntax)
Bookmarks:
⇒concatenation of strings
⇒defining a string
⇒dynamically change string length
⇒rename or shrink a string
⇒string delimiters
⇒substring definitions
defining a string
:
CHARACTER [::] string[*length] [/"inistring"/] [="inistring"] ! [ ] optional
length = a numerical constant known at compile time (
DATA
,
REAL
) to assign the byte count to string, default is 1
inistring = a string constant like "hello world"
examples:
REAL, PARAMETER :: n=100 ! predefines a symbolic constant
CHARACTER :: StringName*n
CHARACTER StringName="initialization string defines length"
CHARACTER StringName * n /"initialization string of length n"/
CHARACTER StringName*123 = "initialization string of length 123"
CHARACTER :: a, b*2, c="xyz", d*n ! lengths are 1, 2, 3, 100 resp.
CHARACTER zoo*n, fish="eel", bird*20/"eagle"/
string delimiters
: almost all non-alfanumeric and non-operator characters, e.g.:
CHARACTER a="double quote", b='single quote', c=%percent%, d=#number_sign#, e=.period.
CHARACTER special = ;string with "double and 'embedded single' quotes" like this;
dynamically change string length
:
ALLOCATE(string, new_string_length)
ALLOCATE is to
expand
a string only
to
rename or shrink a string
use the
ALIAS
function
ALLOCATE (String, 2*
LEN
(String)) ! this doubles current length
substring definitions
:
substring = string(start : [end])
substring = string(4:z) ! starts at byte 4 and extends to the current value of z
substring = string(start : ) ! extends to end of string
ALIAS(string,start, substring,LEN(string)-start+1) ! substring shares memory with string byte start to byte end
substring =
CHAR
(2, 4, "ABC DEF GHI JKL ") ! substring 2 out of 4 equal length substrings is "DEF "
EDIT
(Text=string, Right="x", Mark1, Right="y", Parse=SubStringName)
more examples:
string = "ABC..xyz" ! assign a constant, fill with trailing blanks
textA(i : i+8) = textB
i =
INDEX
(OtherString, "Hello") ! find the location of "Hello"
OtherString = TRIM(string1) // TRIM(string2) // TRIM(string3)!
concatenation of strings
length_of_string =
LEN
(string)
trimmed_length_of_string =
LEN_TRIM
(string)
©2000-2008 Georg Petrich, HicEst Instant Prototype Computing. All rights reserved.
Impressum