I need only words when i split a string , while currently i am getting even spaces
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
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"
Accepted Answer
Guillaume
on 23 Jan 2020
Probably the easiest is to do:
string2 = regexp(yourstring, '\w+', 'match')
10 Comments
Prajwal Venkatesh
on 23 Jan 2020
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.
Prajwal Venkatesh
on 23 Jan 2020
also i want the output to be strings
Walter Roberson
on 23 Jan 2020
string() the cell array that regexp returns.
Walter Roberson
on 23 Jan 2020
\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
Prajwal Venkatesh
on 23 Jan 2020
>> (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');
Walter Roberson
on 23 Jan 2020
Is string2 a string scalar or a non-scalar string array?
Prajwal Venkatesh
on 24 Jan 2020
I am attaching answers.mat
Walter Roberson
on 24 Jan 2020
string2 comes out as missing in that file, and there is no way that that result variable is the output of that regexp() command.
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Tags
See Also
on 23 Jan 2020
on 24 Jan 2020
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)