How can I creat a empty string?
32 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to add string to a string array, but I cannot get the results with length of 3 (like the matrix in the following code), but 4 with a empty string("") for first element. How can I create a empty string? or any alternertive approach for this purpose? Thank you very much
Example:
% for matrix
a = [];
for i = 1:3
a(end+1) = 1;
end
results: a = 1 1 1
% for string
a = string(); % a = strings; a = ""; works same
for i = 1:3
a(end+1) = "1";
end
results: a =
1×4 string array
"" "1" "1" "1"
0 个评论
采纳的回答
更多回答(1 个)
Shiv Kumar
2019-5-14
std::string a;
if(a.empty())
{
}
or
std::string a;
if(!a.empty())
{
}
a = "42";
if(!a.empty())
{
}
1 个评论
Walter Roberson
2019-6-1
This is not MATLAB code, it is C++ code. It is not clear what the relevance of it is?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!