使用CMAKE将字符串拆分为列表的常见方法是什么? [英] What is common way to split string into list with CMAKE?
本文介绍了使用CMAKE将字符串拆分为列表的常见方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下字符串:
set(SEXY_STRING "I love CMake")
then I want to obtain SEXY_LIST
from SEXY_STRING
so I can do
list(LENGTH SEXY_LIST len)
和 len
等于3。
我在网上找到了几个宏,但我真的想知道如何以自然的方式做。
I've found several macros on web, but I really want to know how to do it in "natural" way. This operation seems to be very basic and widely used.
推荐答案
使用;
。我没有看到任何其他方式。
Replace your separator by a ;
. I don't see any other way to do it.
cmake_minimum_required(VERSION 2.8)
set(SEXY_STRING "I love CMake")
string(REPLACE " " ";" SEXY_LIST ${SEXY_STRING})
message(STATUS "string = ${SEXY_STRING}")
# string = I love CMake
message(STATUS "list = ${SEXY_LIST}")
# list = I;love;CMake
list(LENGTH SEXY_LIST len)
message(STATUS "len = ${len}")
# len = 3
这篇关于使用CMAKE将字符串拆分为列表的常见方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文