matlab字串連線

2021-06-02 03:19:08 字數 746 閱讀 2848

在matlab中,想要將兩個字串連線在一起,有以下的方法:

假定有兩個字串

>> str1='iloveyou';str2='123';

方法一:用中括號將str1和str2像矩陣元素一樣包含起來:

>> sc=[str1,str2]

sc =

iloveyou123

(若想驗證str1和str2確實被連線起來,可呼叫length函式測試sc的長度。)

方法二:用strcat函式

>> sb=strcat(str1,str2)

sb =

iloveyou123

注意,strcat函式有許多用法,如下例:

>> strcat(,)

ans =

'redgreen'    'yellowblue'

但下句則結果就不一樣了:

>> strcat(['red','yellow'],['green','blue'])

ans =

redyellowgreenblue

方法三:利用sprintf函式

>> number=123;

>> str=sprintf('%s%d',str1,number)

str =

iloveyou123

利用class(str)得到str的型別為char。

字串連線

輸入n個字串s i 你要把他們按某個順序連線起來,使得字典序最小。1 n 100 每個字串長度 100 字串只包含小寫字母 input 第一行乙個整數n。接下來每行乙個字串s i output 一行乙個字串表示把輸入的n個字串按某個順序連線之後的結果input示例 6 itlooks like an...

字串連線

mysql select abc 123 abc 123 123 1 row in set,1 warning 0.00 sec mysql select 123 123 123 123 246 1 row in set 0.00 sec mysql select 123 123 123 123 2...

字串連線

answer1 char型別 利用cin不包括空格的天然特性,讀取兩個字串,直接按序輸出 include include using namespace std int main return0 answer2 string型別 對於string型別變數,我們可以直接用 進行連線操作 include...