Re: String filtering
- From: "Steve" <nospam_steved94@xxxxxxxxxxx>
- Date: Tue, 27 Sep 2005 18:54:54 -0700
"David Trudgett" <wpower@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:m31x3b6n5v.fsf@xxxxxxxxxxxxxx
>
> Hi all,
>
> I've been puzzling for a little bit over a good way to filter out
> unwanted characters from a string. In particular, I have an unbounded
> string and want to filter out of it all characters not in 'a'..'z',
> 'A'..'Z', '0'..'9'. So far I've only thought of tedious ways to do
> it. Is there an easy way to do it using the string handling facilities
> in Ada? I think I almost got there with the idea of using
> Maps.Character_Set, and so on, but I haven't quite pieced it together
> yet.
>
> Thanks.
>
> David
>
If you're just looking for simple code, I would suggest using the Index and
Delete functions in Ada.Strings.Unbounded. Something along the lines of:
loop
deleteIndex := Index( source, charSet, test => outside );
exit when deleteIndex = 0;
Delete( source, deleteIndex );
end loop;
It's not very efficient, but I think it is about as simple as you can get.
You can probably use Find_Token to get rid of consecutive chunks of
characters you want to remove, but it would be a little bit more messy (and
efficient).
Steve
(The Duck)
> --
>
> David Trudgett
> http://www.zeta.org.au/~wpower/
>
> We must learn to live together as brothers or perish together as
> fools.
>
> -- Martin Luther King, Jr.
>
.
- Follow-Ups:
- Re: String filtering
- From: David Trudgett
- Re: String filtering
- References:
- String filtering
- From: David Trudgett
- String filtering
- Prev by Date: Re: String filtering
- Next by Date: Re: String filtering
- Previous by thread: Re: String filtering
- Next by thread: Re: String filtering
- Index(es):
Relevant Pages
|