
define char*128 c
let c "Hello world!"

! Check reading substring:
if c[7:11].ne."world" then
  message e demo "Substring error 1"
  return error
endif

message i demo "Should echo ""world"":"
examine c[7:11]

! Check writing substring:

let c[7:11] "gentlemen"  ! NB: 9 characters into 5
if c.ne."Hello gentl!" then
  message e demo "Substring error 2"
  return error
endif

let c[7:11] "Sir"  ! NB: 3 characters into 5
if c.ne."Hello Sir  !" then
  message e demo "Substring error 3"
  return error
endif

! Check array of strings

define char*10 d[2,2]
let d[1,1] "abcd"
let d[2,1] "efgh"
let d[1,2] "ijkl"
let d[2,2] "mnop"


! Check reading substring in subarray

if d[1,2][2:3].ne."jk" then
  message e demo "Substring error 4"
  return error
endif

message i demo "Should echo ""fg"":"
examine d[2,1][2:3]

! Check writing substring in subarray

let d[2,2] "qrs"
if d[2,2].ne."qrs" then
  message e demo "Substring error 5"
  return error
endif

let d[1,2][1:2] "XYZ"
if d[1,2].ne."XYkl" then
  message e demo "Substring error 6"
  return error
endif

let d[2,2][3:4] 'd[1,1][1:2]' /upper
if d[2,2].ne."qrAB" then
  message e demo "Substring error 7"
  return error
endif


! Check aliases
define alias a d[1,2][2:3]
if a.ne."Yk" then
  message e demo "Substring error 8"
  return error
endif

let a "23"
if d[1,2].ne."X23l" then
  message e demo "Substring error 9"
  return error
endif
