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:
how to insert space between strings using strcat?

Subject: how to insert space between strings using strcat?

From: Jane

Date: 21 Aug, 2006 18:22:00

Message: 1 of 7

Hi,
  I tried to use strcat to concatenate different strings, but seems
that strcat ignore blank strings. For example,
strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
know how to create the space between different strings?

  Thanks,
  Jane

Subject: how to insert space between strings using strcat?

From: Richard Brown

Date: 21 Aug, 2006 16:19:25

Message: 2 of 7


Jane wrote:

> Hi,
> I tried to use strcat to concatenate different strings, but seems
> that strcat ignore blank strings. For example,
> strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
> know how to create the space between different strings?

strcat chomps trailing spaces in strings. You might want to just use
matrix concatenation (horzcat):
['A', ' ', 'B']

otherwise, try sprintf for more flexibility

HTH

Richard

Subject: how to insert space between strings using strcat?

From: Michael Wild

Date: 22 Aug, 2006 08:53:50

Message: 3 of 7

Richard Brown wrote:
> Jane wrote:
>
>> Hi,
>> I tried to use strcat to concatenate different strings, but seems
>> that strcat ignore blank strings. For example,
>> strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
>> know how to create the space between different strings?
>
> strcat chomps trailing spaces in strings. You might want to just use
> matrix concatenation (horzcat):
> ['A', ' ', 'B']
>
> otherwise, try sprintf for more flexibility
>
> HTH
>
> Richard
>

or enclose the string in {} which will tell strcat to respect spaces.

strcat({'hello '},{'Anna','Jane','Mark'});
or
strcat('hello',{' '},{'Anna','Jane','Mark'});


will give you what you want.


michael

michael

Subject: how to insert space between strings using strcat?

From: Steven Lord

Date: 22 Aug, 2006 10:38:42

Message: 4 of 7


"Jane" <whisperofbreeze@hotmail.com> wrote in message
news:ef3edff.-1@webcrossing.raydaftYaTP...
> Hi,
> I tried to use strcat to concatenate different strings, but seems
> that strcat ignore blank strings. For example,
> strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
> know how to create the space between different strings?

Yes, this is the documented behavior of STRCAT.

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

As stated in the third line of the Description section of that page, as well
as Richard and Michael's posts, use the cell array syntax or use plain old
concatenation with [].

--
Steve Lord
slord@mathworks.com

Subject: how to insert space between strings using strcat?

From: kaved jindal

Date: 19 Jan, 2007 01:07:18

Message: 5 of 7

Jane wrote:
>
>
> Hi,
> I tried to use strcat to concatenate different strings, but seems
> that strcat ignore blank strings. For example,
> strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
> know how to create the space between different strings?
>
> Thanks,
> Jane

Subject: how to insert space between strings using strcat?

From: Michael Salloker

Date: 19 Jan, 2007 11:19:33

Message: 6 of 7

kaved jindal schrieb:
> Jane wrote:
>>
>> Hi,
>> I tried to use strcat to concatenate different strings, but seems
>> that strcat ignore blank strings. For example,
>> strcat('A','B') is the same as strcat('A',' ','B'). Does anybody
>> know how to create the space between different strings?
>>
>> Thanks,
>> Jane

 From the strcat documentation:

Trailing spaces in character array inputs are ignored and do not appear
in the output. This is not true for inputs that are cell arrays of
strings. Use the concatenation syntax [s1 s2 s3 ...] to preserve
trailing spaces.

Michael

Subject: how to insert space between strings using strcat?

From: Tsolmonbaatar Khurelbaatar

Date: 25 Apr, 2013 05:21:08

Message: 7 of 7

Thank you very much. It helped me a lot.

Tags for this Thread

No tags are associated with 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