cmake_minimum_required(VERSION 3.22)
project(cmake_string)
set(STR1 "cmake string test")
string(SUBSTRING ${STR1} ${pos} ${len} substr)
message(${substr})
以上代码在命令行输入cmake -S . -B build
会报错 string sub-command SUBSTRING requires four arguments.这是因为pos和 len还没有定义,定义pos和 len 后,
cmake_minimum_required(VERSION 3.22)
project(cmake_string)
set(STR1 "cmake string test")
set(pos 6)
set(len 6)
string(SUBSTRING ${STR1} ${pos} ${len} substr)
message(${substr})
命令行重新输入cmake -S . -B build
输出为string,(因为string在"camke string test"中从零开始的第六个位置,长度为6)