Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

split text string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bamba Bolo - 10 Jul 2008 21:26 GMT
Hi, I have multiple text strings consisting of two words
separated with a "tab" looking something like below:

one    two

now how do you do to split this string to two separate
strings, in this case it would be split to the strings 'one'
and 'two'.

Thanks
Walter Roberson - 10 Jul 2008 21:43 GMT
>Hi, I have multiple text strings consisting of two words
>separated with a "tab" looking something like below:

>one    two

>now how do you do to split this string to two separate
>strings, in this case it would be split to the strings 'one'
>and 'two'.

regexp(TheString, '([^ \t][^\t]*)', 'match')

This expression is a bit more complicated than is at first
obvious because I detect that there is a space after the tab
but your output does not want the space as part of the output string.
You have not specified, though, what you want to have happen if there
are spaces within the fields.
Signature

 "Product of a myriad various minds and contending tongues, compact of
 obscure and minute association, a language has its own abundant and
 often recondite laws, in the habitual and summary recognition of
 which scholarship consists."                -- Walter Pater

Nitin Chhabra - 11 Jul 2008 07:05 GMT
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g55s9j$hhc$1@canopus.cc.umanitoba.ca>...
> >Hi, I have multiple text strings consisting of two words
> >separated with a "tab" looking something like below:
[quoted text clipped - 12 lines]
> You have not specified, though, what you want to have happen if there
> are spaces within the fields.

Hi,

If there are just two words, strtok could be used.
help strtok for more.

with regards,
Nitin
us - 11 Jul 2008 07:41 GMT
"Bamba Bolo":
<SNIP a matter of english...

> two words separated with a "tab" looking something like
below:
> one    two
> now how do you do to split this string to two separate
> strings...

one of the many solutions

    s=sprintf('one\ttwo three\tfour');
    r=regexp(s,'\t','split')
% r = 'one' 'two three' 'four'

us
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.