Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!24g2000yqm.googlegroups.com!not-for-mail
From: Rune Allnor <allnor@tele.ntnu.no>
Newsgroups: comp.soft-sys.matlab
Subject: Re: manipulating strings
Date: Tue, 7 Jul 2009 11:27:54 -0700 (PDT)
Organization: http://groups.google.com
Lines: 24
Message-ID: <746e9354-c35c-4296-81b3-751c8e5e7f05@24g2000yqm.googlegroups.com>
References: <87c67726-964b-48ce-80f0-a50d24b62cd1@26g2000yqk.googlegroups.com>
NNTP-Posting-Host: 77.16.114.230
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1246991275 19553 127.0.0.1 (7 Jul 2009 18:27:55 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 7 Jul 2009 18:27:55 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 24g2000yqm.googlegroups.com; posting-host=77.16.114.230; 
	posting-account=VAp5gAkAAAAmkCze5hvZtMeedpZWNthI
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; 
	Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 
	3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:553510

On 7 Jul, 13:29, arun <aragorn1...@gmail.com> wrote:
> Hi,
>
> suppose I have a string A whose size is 1*10^7. I would now like to
> remove certain characters in the string. I tried strfind and regexprep
> as follows
>
> A(strfind(A, ',')) = ''; %replace entries with a comma with nothing
> and then i repeat this for all numbers from 0 to 9 and for "space".
>
> Alternative efficient way i hoped would be,
> A = regexprep(A, "[0-9, ]", '');
> but the first expression takes for ever as the vector is long

Every time this finds a match, the vector is shortened by one
character, meaning you need to allocate space re-shuffle the
contents every time one finds a hit. This would probably be
better:

rexp = '[^0-9, ]';
idx = regex(A,rexp);
A = A(idx);

Rune