Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: split text string

Subject: split text string

From: Bamba Bolo

Date: 10 Jul, 2008 20:26:02

Message: 1 of 4

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

Subject: split text string

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 10 Jul, 2008 20:43:31

Message: 2 of 4

In article <g55r8q$f4c$1@fred.mathworks.com>,
Bamba Bolo <hooana@hotmail.com> wrote:
>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.
--
  "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

Subject: split text string

From: Nitin Chhabra

Date: 11 Jul, 2008 06:05:08

Message: 3 of 4

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g55s9j$hhc$1@canopus.cc.umanitoba.ca>...
> In article <g55r8q$f4c$1@fred.mathworks.com>,
> Bamba Bolo <hooana@hotmail.com> wrote:
> >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.
> --
> "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

Hi,

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

with regards,
Nitin

Subject: split text string

From: us

Date: 11 Jul, 2008 06:41:02

Message: 4 of 4

"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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sprintf us 11 Jul, 2008 02:45:17
regexp us 11 Jul, 2008 02:45:17
code us 11 Jul, 2008 02:45:16
text split Bamba Bolo 10 Jul, 2008 16:35:07
string Bamba Bolo 10 Jul, 2008 16:35:07
text string Bamba Bolo 10 Jul, 2008 16:35:07
split Bamba Bolo 10 Jul, 2008 16:35:07
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics