given String 'Foo <nowiki>Bar</nowiki> Baz' yield String 'Foo Baz'

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

given String 'Foo <nowiki>Bar</nowiki> Baz' yield String 'Foo Baz'

Squeak - Dev mailing list
Hi folks,

I did not see anything obvious to do the above, and I am writing some really ugly code to get the task done.

Is anybody aware of a simple message send like...

'Foo <nowiki>Bar</nowiki> Baz' removeAllBetween:'<nowiki>' and: '</nowiki>'.
thx in advance.



Reply | Threaded
Open this post in threaded view
|

Re: given String 'Foo <nowiki>Bar</nowiki> Baz' yield String 'Foo Baz'

Squeak - Dev mailing list


On 25 Dec 2020, at 12:28, gettimothy via Squeak-dev <[hidden email]> wrote:

'Foo <nowiki>Bar</nowiki> Baz' removeAllBetween:'<nowiki>' and: '</nowiki>'.

a := 'Foo <nowiki>Bar</nowiki> Baz'.
s:= Scanner new.
toks := s typedScanTokens:  a.
sel := ''.
level := 0.
toks do: [:t|
t caseOf: {
[#<] -> [level:=1].
[#</] ->  [level:=2].
[#>] -> [level =2 ifTrue:[sel:=sel, ' '. level:=0]].
}
otherwise: [
level = 0 ifTrue:[sel := sel, t]
].
].
sel




Reply | Threaded
Open this post in threaded view
|

Re: given String 'Foo <nowiki>Bar</nowiki> Baz' yield String 'Foo Baz'

timrowledge
In reply to this post by Squeak - Dev mailing list
Depends on your needs -

> On 2020-12-25, at 9:28 AM, gettimothy via Squeak-dev <[hidden email]> wrote:
>
>
> 'Foo <nowiki>Bar</nowiki> Baz' removeAllBetween:'<nowiki>' and: '</nowiki>'.
> thx in advance.

For a one-off case, maybe some of the #findTokenXXX methods? Maybe #parseTokens: would help - it's part of the HTML handling stuff.

For bigger duty, probably time to look into the regexp methods; there's a bunch of likely suspects in the messagenamebrowser.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: BPB: Branch on Program Bug



Reply | Threaded
Open this post in threaded view
|

Re: given String 'Foo <nowiki>Bar</nowiki> Baz' yield String 'Foo Baz'

Eliot Miranda-2
In reply to this post by Squeak - Dev mailing list
Hi Tim,

On Fri, Dec 25, 2020 at 9:29 AM gettimothy via Squeak-dev <[hidden email]> wrote:
Hi folks,

I did not see anything obvious to do the above, and I am writing some really ugly code to get the task done.

Is anybody aware of a simple message send like...

'Foo <nowiki>Bar</nowiki> Baz' removeAllBetween:'<nowiki>' and: '</nowiki>'.
thx in advance.

You can rely on your own parsing, but if you're at all likely to expand into a broader HTML space then explore the HTML Framework.  For example, this doesn't do what you want but it gets you close and is generally powerful enough for any and all HTML parsing tasks.

(HTMLParser parse: 'Foo <nowiki>Bar</nowiki> Baz') contents last textualContents => 'Foo Bar Baz'


_,,,^..^,,,_
Happy Holidays, Eliot