Thread Subject: How to insert a space while doing strcat(a,b)

Subject: How to insert a space while doing strcat(a,b)

From: Elangovan

Date: 1 Jul, 2009 17:11:01

Message: 1 of 6

hi all,

How to insert a space while doing strcat(a,b).
for eg:
a = 'aaaa'
b = 'bbbb'

strcat(a,b) gives 'aaaabbbb'

i want 'aaaa bbbb'.

How do i do that ?

Subject: How to insert a space while doing strcat(a,b)

From: Steven Lord

Date: 1 Jul, 2009 17:18:22

Message: 2 of 6


"Elangovan " <ea39@njit.edu> wrote in message
news:h2g5b5$8qg$1@fred.mathworks.com...
> hi all,
>
> How to insert a space while doing strcat(a,b).
> for eg:
> a = 'aaaa'
> b = 'bbbb'
>
> strcat(a,b) gives 'aaaabbbb'
>
> i want 'aaaa bbbb'.
>
> How do i do that ?

Either use square brackets to concatenate instead of using STRCAT, or append
the space at the beginning of the string b, or make a cell array of strings
from a and b.

See the third paragraph in the Description section of the reference page for
STRCAT.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/strcat.html

--
Steve Lord
slord@mathworks.com

Subject: How to insert a space while doing strcat(a,b)

From: Johnathan

Date: 1 Jul, 2009 17:20:02

Message: 3 of 6

try :
newstring=[a,' ',b];

lots of luck!
--John





"Elangovan " <ea39@njit.edu> wrote in message <h2g5b5$8qg$1@fred.mathworks.com>...
> hi all,
>
> How to insert a space while doing strcat(a,b).
> for eg:
> a = 'aaaa'
> b = 'bbbb'
>
> strcat(a,b) gives 'aaaabbbb'
>
> i want 'aaaa bbbb'.
>
> How do i do that ?

Subject: How to insert a space while doing strcat(a,b)

From: us

Date: 1 Jul, 2009 17:22:02

Message: 4 of 6

"Elangovan " <ea39@njit.edu> wrote in message <h2g5b5$8qg$1@fred.mathworks.com>...
> hi all,
>
> How to insert a space while doing strcat(a,b).
> for eg:
> a = 'aaaa'
> b = 'bbbb'
>
> strcat(a,b) gives 'aaaabbbb'
>
> i want 'aaaa bbbb'.
>
> How do i do that ?

one of the many(!) solutions

     a='aaaa';
     b='bb';
     c=sprintf('%s %s',a,b); % <- this is very versatile...

us

Subject: How to insert a space while doing strcat(a,b)

From: Xing zhao

Date: 1 Jul, 2009 17:29:02

Message: 5 of 6

"Elangovan " <ea39@njit.edu> wrote in message <h2g5b5$8qg$1@fred.mathworks.com>...
> hi all,
>
> How to insert a space while doing strcat(a,b).
> for eg:
> a = 'aaaa'
> b = 'bbbb'
>
> strcat(a,b) gives 'aaaabbbb'
>
> i want 'aaaa bbbb'.
>
> How do i do that ?

en, not sure what's your point.

but you can try like this,

strcat(a,{' '},b)

or

s = {a, ' ', b};
[s{:}]

Cheers.

Xing

Subject: How to insert a space while doing strcat(a,b)

From: Elangovan

Date: 1 Jul, 2009 17:29:02

Message: 6 of 6

Thanks.. got it working now with square brackets.

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 1 Jul, 2009 13:24:09
code us 1 Jul, 2009 13:24:09
strcat Elangovan 1 Jul, 2009 13:14:05
rssFeed for this Thread

Contact us at files@mathworks.com