Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
string manipulation delimiter

Subject: string manipulation delimiter

From: sushma sharma

Date: 16 Feb, 2008 18:29:01

Message: 1 of 9

hi,

i have a cell array of strings, a =

'1'
'9'
'12'
'1/10'
'1/10'

how can i delimit on '/', so that if there is a '/' in the
string i get the elements to teh right of the '/', and if
there is no '/', i get the element as it is.

the output would be

1
9
12
1
1

so far i've tried strfind(a,'/') and haven't made much progress.

any help would be appreciated!

thank you once again!

sushma

Subject: string manipulation delimiter

From: sushma sharma

Date: 16 Feb, 2008 18:45:03

Message: 2 of 9


using token = strtok(a, '/') i can get everything to the
left side of the '/'.

is there any way i can get what lies to the right side of
the '/', (and otherwise 0 if there is no '/' in the string)

thanks!

sushma

Subject: string manipulation delimiter

From: us

Date: 16 Feb, 2008 18:54:02

Message: 3 of 9

"sushma sharma":
<SNIP regular expression evergreen...

one of the many solutions

     s={
             '1'
             '9'
            '12'
          '1/10'
          '1/10'
     };
     r=regexp(s,'\d+(($)|(?=/))','match','once')
%{
     '1'
     '9'
     '12'
     '1'
     '1'
%}

us

Subject: string manipulation delimiter

From: sushma sharma

Date: 16 Feb, 2008 19:01:03

Message: 4 of 9

that give what is to the left side of the '/' and otherwise
returns the character if no '/' is present.

my question is how do i get what is to the RIGHT side of the
'/' and otherwise get a 0 if no '/' is present.

thank you for your assistance!

sushma

Subject: string manipulation delimiter

From: us

Date: 16 Feb, 2008 19:16:02

Message: 5 of 9

"sushma sharma":
<SNIP being fuzzy about a solution...

> that give what is to the left side of the '/' and
otherwise returns the character if no '/' is present...

which is EXACTLY what your example (OP) looks like(?)

us

Subject: string manipulation delimiter

From: us

Date: 16 Feb, 2008 19:18:02

Message: 6 of 9

"sushma sharma":
<SNIP flip-flopping from left to right..

now, since you insist...

     s={
              '1'
              '9'
             '12'
          '1/101'
          '1/5'
     };
     m=regexp(s,'\d+($)|(?<=/)','match','once')
%{
     '1'
     '9'
     '12'
     '101'
     '5'
%}

us

Subject: string manipulation delimiter

From: sushma sharma

Date: 16 Feb, 2008 19:28:01

Message: 7 of 9

     s={
              '1'
              '9'
             '12'
          '1/101'
          '1/5'
     };


i'm trying to get the output to be:

0
0
0
101
5

[everything to the right of the '/'. if no '/' is present,
then '0']

desperately need help!!!

thanks!

Subject: string manipulation delimiter

From: us

Date: 16 Feb, 2008 19:37:01

Message: 8 of 9

"sushma sharma":
<SNIP YET another request...

can you please make up your mind! it's getting a bit
tedious to operate at this level of uncertainty...

us

Subject: string manipulation delimiter

From: Martin Hewitson

Date: 16 Feb, 2008 20:41:01

Message: 9 of 9

"sushma sharma" <ssharma@ynospamahoo.com> wrote in message
<fp7a1d$db4$1@fred.mathworks.com>...
> hi,
>
> i have a cell array of strings, a =
>
> '1'
> '9'
> '12'
> '1/10'
> '1/10'
>
> how can i delimit on '/', so that if there is a '/' in the
> string i get the elements to teh right of the '/', and if
> there is no '/', i get the element as it is.
>
> the output would be
>
> 1
> 9
> 12
> 1
> 1
>
> so far i've tried strfind(a,'/') and haven't made much progress.
>
> any help would be appreciated!
>
> thank you once again!
>
> sushma


>> [s,r] = strtok(str, '/');

splits the string 'str' into two parts. The part before the '/' appears in 's', the
part after in 'r' - the remainder.

Maybe this can help? You can test if r is empty

if isempty(r)
    ret = str;
else
    ret = r;
end

Tags for this Thread

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.

Contact us