I need only words when i split a string , while currently i am getting even spaces
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
string2=split(string(result{1,hh}(ss,1)),[" ",",","(",")","-"])
>> string2
string2 =
8×1 string array
"Secure"
"VPDM"
"to"
"Ebay"
"housing"
""
"optional"
""
I need the output to be
"Secure"
"VPDM"
"to"
"Ebay"
"housing"
"optional"
採用された回答
Probably the easiest is to do:
string2 = regexp(yourstring, '\w+', 'match')
10 件のコメント
I can sometimes have numbers in there too
What should i do then?
Caution: \w will not match ' or - characters or period.
Don't pay $29.95 for e-mail!
Would get broken into
Don
t
pay
29
95
for
e
mail
It can be difficult to define what "words" are in English.
also i want the output to be strings
string() the cell array that regexp returns.
\w already includes the digits. It would not include decimal points or commas or positive or negative signs or scientific notation. If you need to include numbers it is best to define exactly which numeric formats you will support.
Floating point numbers are always a nuisance to write expressions for, especially if you permit leading 0 to be omitted such as .716e-3 instead of 0.716e-3
>> (regexp(string2, '\w+', 'match'))
ans =
8×1 cell array
{["Secure" ]}
{["VPDM" ]}
{["to" ]}
{["Ebay" ]}
{["housing" ]}
{0×0 string }
{["optional"]}
{0×0 string }
Error using string
Conversion from cell failed. Element 6 must be
convertible to a string scalar.
This is the issue
Can you attach your string2 and/or result in a .mat file so we can use it?
save('answers.mat', 'string2', 'result');
Is string2 a string scalar or a non-scalar string array?
I am attaching answers.mat
string2 comes out as missing in that file, and there is no way that that result variable is the output of that regexp() command.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
