Need an elegant way to solve a simple problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need an elegant way to solve a simple problem

CdAB63
I have a ByteString line. I want to strip blanks and tabs at end of it. Blanks and tabs allowed between words. MxMatcher looks a bit like using a gun to kill a fly. Any suggestion about a time effective way of solving the problem? (obvious way: asOrderedCollection and then backtrack killing spaces & tabs until find non space/tab char).

Best regards,

CdAB
--
The information contained in this message is confidential and intended to the recipients specified in the headers. If you received this message by error, notify the sender immediately. The unauthorized use, disclosure, copy or alteration of this message are strictly forbidden and subjected to civil and criminal sanctions.

==

This email may be signed using PGP key ID: 0x4134A417



signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Need an elegant way to solve a simple problem

marcel.taeumel
You can use #withBlanksTrimmed (and #withoutLineEndings) for that.

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: Need an elegant way to solve a simple problem

Levente Uzonyi-2
In reply to this post by CdAB63
If stripping leading blanks is okay, then you can use #withBlanksTrimmed.
Otherwise you can use the following oneliner:

string copyFrom: 1 to: (string lastIndexOfAnyOf: CharacterSet nonSeparators startingAt: string size ifAbsent: string size)

Levente

On Tue, 22 Sep 2015, Casimiro - GMAIL wrote:

> I have a ByteString line. I want to strip blanks and tabs at end of it. Blanks and tabs allowed between words. MxMatcher looks a bit like using a gun to kill a fly. Any suggestion about a time effective way
> of solving the problem? (obvious way: asOrderedCollection and then backtrack killing spaces & tabs until find non space/tab char).
>
> Best regards,
>
> CdAB
> --
> The information contained in this message is confidential and intended to the recipients specified in the headers. If you received this message by error, notify the sender immediately. The unauthorized use,
> disclosure, copy or alteration of this message are strictly forbidden and subjected to civil and criminal sanctions.
>
> ==
>
> This email may be signed using PGP key ID: 0x4134A417
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Need an elegant way to solve a simple problem

CdAB63
Thnx Levente & Marcel. Problem solved with #withBlanksTrimmed.


Em 22-09-2015 11:06, Levente Uzonyi escreveu:
If stripping leading blanks is okay, then you can use #withBlanksTrimmed. Otherwise you can use the following oneliner:

string copyFrom: 1 to: (string lastIndexOfAnyOf: CharacterSet nonSeparators startingAt: string size ifAbsent: string size)

Levente


--
The information contained in this message is confidential and intended to the recipients specified in the headers. If you received this message by error, notify the sender immediately. The unauthorized use, disclosure, copy or alteration of this message are strictly forbidden and subjected to civil and criminal sanctions.

==

This email may be signed using PGP key ID: 0x4134A417



signature.asc (836 bytes) Download Attachment