How to cut the end of a string which follows a special character?

For example: 'sahdklsjf_sdfs' to 'sahdklsjf'

2 件のコメント

Mr M.
Mr M. 2015 年 5 月 26 日
The following is not working for me: source = mfilename(1:end-5) Why? But this works: source = mfilename source = source(1:end-5) Why?
David Young
David Young 2015 年 5 月 26 日
mfilename is a function, so it can't be indexed. Assigning its result to a variable then gives you a string which can be indexed.

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

回答 (3 件)

Jan
Jan 2015 年 5 月 26 日

3 投票

S = 'sahdklsjf_sdfs'
Part = strtok(S, '_');
Thorsten
Thorsten 2015 年 5 月 26 日

1 投票

regexp('sahdklsjf_sdfs', '(^[a-zA-Z]*)', 'match')
Jos (10584)
Jos (10584) 2015 年 5 月 26 日

0 投票

Many options, including:
str = 'sahdklsjf_sdfs'
out1 = str(1:find([str '_']=='_',1,'first'))
Also take a look at TEXTSCAN

カテゴリ

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

質問済み:

2015 年 5 月 26 日

回答済み:

2015 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by