How can I creat a empty string?

조회 수: 30 (최근 30일)
Yang
Yang 2019년 5월 14일
댓글: Walter Roberson 2019년 6월 1일
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"

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 5월 14일
% for string
a = string([]);
for i = 1:3
a(end+1) = "1";
end

추가 답변 (1개)

Shiv  Kumar
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
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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by