Hi everyone,
I have a column string in this format
"injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"
I want to extract the numeric part that starts with 9 like 94577 from roow one for instance. Can anyone help please? Thank you.

 採用された回答

Paul
Paul 2021 年 11 月 17 日

0 投票

str = ["injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"]
str = 7×1 string array
"injection-0:94577)" "injection-0:94578)" "injection-0:94579)" "injection-0:94580)" "injection-0:94581)" "injection-0:94582)" "injection-0:94583)"
newstr = extractBefore(extractAfter(str,":"),")")
newstr = 7×1 string array
"94577" "94578" "94579" "94580" "94581" "94582" "94583"

3 件のコメント

Mahdi Khademishamami
Mahdi Khademishamami 2021 年 11 月 17 日
編集済み: Mahdi Khademishamami 2021 年 11 月 17 日
Thank you! What about converting the newstr to an array? Should I use str2num?
Paul
Paul 2021 年 11 月 17 日
I would just use double()
str = ["injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"];
newstr = extractBefore(extractAfter(str,":"),")");
d = double(newstr)
d = 7×1
94577 94578 94579 94580 94581 94582 94583
Mahdi Khademishamami
Mahdi Khademishamami 2021 年 11 月 17 日
Thanks again!

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

その他の回答 (1 件)

per isakson
per isakson 2021 年 11 月 17 日

1 投票

Try
>> extractBetween( "injection-0:94582)", ":", ")" )
ans =
"94582"

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by