Re: String filtering



"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.
>


.



Relevant Pages

  • Form Filter length limitation
    ... 2400 characters into the form filter property. ... So as a workaround I tried to place the filter in a global string variable. ...
    (microsoft.public.access.formscoding)
  • IF Function - Begins With
    ... How do I apply the "begins with" filter to an IF statement? ... like to test a match on the first 3 characters of a string in a given ... Prev by Date: ...
    (microsoft.public.excel.misc)
  • Re: CRecordset::m_strFilter - what is the character limit? (newbie)
    ... > What is the maximum length (number of characters) can I make the filter ... > string containing all those filter texts exceeds the max length of the ... I think thats what 'joins' are for. ...
    (microsoft.public.vc.language)
  • Re: extracting the text out of a binary file
    ... You can filter the string to just accept range of the numbers and letters. ... > to get at BUT there are a lot of junk characters and white space ... I was wondering if the binaryreader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)