Strings in Managed COBOL
*> Escape sequences
x"0a" *> line-feed
x"09" *> tab
"\" *> backslash
"" *> quote
*> String concatenation
01 school string value "Harding" & x"09".
*> school is "Harding (tab) University"
set school to school & "University"
*> Chars
01 letter character.
01 word character occurs any.
set letter to school::Chars(0) *> letter is H
set letter to type Convert::ToChar(65) *> letter is A
set letter to 65 as character *> same thing
set word to school::ToCharArray *>word holds Harding
*> String literal
01 msg string value "File is c:\temp\x.dat".
*> String comparison
01 mascot string value "Beatles".
if mascot = "Beatles" *> true
if mascot::Equals("Beatles") *> true
if mascot::ToUpper::"Equals"("BEATLES") *> true
if mascot::CompareTo("Beatles") = 0 *> true
*> Substring
set s to mascot::Substring(1, 3) *> s is "eat"
*> Replacement
set s to mascot::Replace("Beatl" "Monke") *> s is "Monkees"
*> Split
01 names string value "John,Paul,George,Ringo".
01 parts string occurs any.
set parts to names::Split(",")
*> Date to string
01 dt type DateTime value new DateTime(1973, 10, 12).
01 s string.
set s to dt::ToString("MMM dd, yyyy") *> Oct 12, 1973
*> int to string
01 x string.
01 y binary-long value 2.
set x to type x::ToString *> x is "2"
*> string to int
01 x binary-long.
set x to type Convert::ToInt32("-5") *> x is -5
*> Mutable string
01 buffer type System.Text.StringBuilder
value new System.Text.StringBuilder("two ").
invoke buffer::Append("three ")
invoke buffer::Insert(0, "one ")
invoke buffer::Replace("two" "TWO"
display buffer *> Prints "one TWO three"