Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Split and search strings

2 ビュー (過去 30 日間)
Philipp Mueller
Philipp Mueller 2020 年 7 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello,
First Question:
I have one string called DetailInfo
DetailInfo="C_t=3;G_B=0;E_F_li=0;ES_Fi_e=0;N_Fee=0;twixx=6";
split2 = regexp(DetailInfo, ';', 'split')
Result -> I got a 1*7 string array -> C_t=3;G_B=0;E_F_li=0;ES_Fi_e=0;N_Fee=0;twixx=6;
But i want a 1*7 string array with only the value after the = sign ->3;0;........
How does it work?
Second question:
How can i check if after I+3 random numbers like l069_ is something. For example 2. String U2_walde_fuckhfg! result=U2_walde_fuckhfg
  1. String: 04660_s_str_uufi_a0560_t5_fs_v22_l069_
  2. String: 04660_s_str_uufi_a0560_t5_fs_v22_l066_U2_walde_fuckhfg
  3. String: 0466550_s_str_uufi_a00_t5_fs_v22_l067_U2_walde_fuck
Thank you
  2 件のコメント
Johannes Fischer
Johannes Fischer 2020 年 7 月 7 日
Using regular expressions is the way to go for these kind of problems, so you are on the right track already.
I suggest you take some time and introduce yourself into regular expressions, believe me it is a time well spent. There is an introduction by MathWorks here, but Im sure you will find many other useful introductions online (at quick glance, the MathWorks introduction is probably not suited for people who never worked with regular expressions before). When you are familiar with the basics have a look at 'capture groups', this is what you need when you want to extract information from a string.
I'd like to suggest that you use more family friendly examples next time. These might keep some people from answering your questions...
Philipp Mueller
Philipp Mueller 2020 年 7 月 7 日
Ok, in anderen Foren (nicht Matlab) wurde mir gesagt ich solle auf höfliche Anreden und andere Dinge verzichten und mich auf das wesentliche beschränken. lg

回答 (1 件)

dpb
dpb 2020 年 7 月 7 日
There's new set of higher-level functions that will do the first...
>> str2double(extractAfter(split(DetailInfo,";"),"="))
ans =
3
0
0
0
0
6
>>

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by