Thread Subject: strcat deleting special letters

Subject: strcat deleting special letters

From: Corinna Schmitt

Date: 10 Aug, 2007 08:01:31

Message: 1 of 4

Hallo together,

I want to concatenete strings. My idea is:

source ='BeispielTabelle_250707.txt';
resultfile=strcat(source,'aidaForTestaida.txt');

--> resultfile =
BeispielTabelle_250707.txtaidaForTestaida.txt

The source comes from an imput by the user and must be
something.txt!
How can I now cut the last 4 letters in general off
(here: .txt, later also .xls, .doc ...)? source should be
only 'something' (here: 'BeispielTabelle_250707' and then
resultfile = 'BeispielTabelle_250707aidaForTestaida.txt')

Any idea?

Thanks, Corinna

Subject: strcat deleting special letters

From: Corinna Schmitt

Date: 10 Aug, 2007 08:09:14

Message: 2 of 4

Hallo again,

I forgot to say that the length of the string source must
be variable because it is a user input.

Corinna


Subject: strcat deleting special letters

From: Titus

Date: 10 Aug, 2007 08:29:21

Message: 3 of 4


"Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag
news:f9h60r$mvk$1@fred.mathworks.com...
> Hallo together,
>
> I want to concatenete strings. My idea is:
>
> source ='BeispielTabelle_250707.txt';
> resultfile=strcat(source,'aidaForTestaida.txt');
>
> --> resultfile =
> BeispielTabelle_250707.txtaidaForTestaida.txt
>
> The source comes from an imput by the user and must be
> something.txt!
> How can I now cut the last 4 letters in general off
> (here: .txt, later also .xls, .doc ...)? source should be
> only 'something' (here: 'BeispielTabelle_250707' and then
> resultfile = 'BeispielTabelle_250707aidaForTestaida.txt')
>
> Any idea?
>
> Thanks, Corinna

Hi Corinna,
two methods: the simple one is
resultfile = [source(1:end-4) 'aidaForTestaida.txt'];

or somewhat more involved (in case it's not .txt but .html,
you may even keep the extension the same):
[sourcepath,sourcename,sourceext]=fileparts(source);
resultfile = [sourcename 'aidaForTestaida' sourceext];

Titus


Subject: strcat deleting special letters

From: Michael Wild

Date: 10 Aug, 2007 08:28:07

Message: 4 of 4

Corinna Schmitt wrote:
> Hallo again,
>
> I forgot to say that the length of the string source must
> be variable because it is a user input.
>
> Corinna
>
>


first of, strings are character arrays, and thus can be indexed. if you
want to leave away the four last characters, use

str = 'something.txt';
str1 = str(1:end-4);

however, what you want, is stripping away the file extension. there are
much more appropriate ways to do this. have a look at the FILEPARTS
function. it should do exactly what you need.


michael

Tags for this Thread

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.

rssFeed for this Thread

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.

Contact us at files@mathworks.com