Splitting based on delimiter but only once

37 ビュー (過去 30 日間)
Sanjana Sankar
Sanjana Sankar 2019 年 7 月 22 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 22 日
Hello!
I know how to split a string entirely based on a delimiter. But I would like to know how to do the following split
Input: Country ˈk ʌ n t r i
Output: Country
and ˈk ʌ n t r i
That is, I would like to use the first 'space' as a delimiter. But not the other spaces between the letters.
Please let me know how to make this possible.
Thanks in advance!
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 22 日
Sorry, for me the question is still unclear? The input and oytput seems same (added and and 2nd line)
Sanjana Sankar
Sanjana Sankar 2019 年 7 月 22 日
Input is a single string "Country ˈk ʌ n t r i"
Output must be 2 strings. "Country" and "ˈk ʌ n t r i" separately.

サインインしてコメントする。

回答 (3 件)

Stephen23
Stephen23 2019 年 7 月 22 日
>> S = 'Country ˈk ʌ n t r i';
>> C = regexp(S,' ','split','once')
C =
'Country' 'ˈk ʌ n t r i'

infinity
infinity 2019 年 7 月 22 日
Hello,
You can refer this idea to extend you the case of longer string
clear
input = 'Country ˈk ʌ n t r i';
[val,idx] = ismember(' ˈ',input);
n =length(idx);
output = cell(1,n);
for i = 1:n
if i == 1
output{i} = input(1:idx(i)-1);
else
output{i} = input(idx(i)+1:end);
end
end

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 22 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 22 日
input='Country k ʌ n t r i';
str1=strtok(input)
str2=extractAfter(input,str1)
output={str1,str2}
Results:
str1 =
'Country'
str2 =
' k ? n t r i'
output =
1×2 cell array
'Country' ' k ? n t r i'

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by