Fwd: String insertion

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

Fwd: String insertion

Simon Denier-3


Begin forwarded message:

From: Simon Denier <[hidden email]>
Date: 19 août 2010 18:30:51 HAEC
To: A friendly place where any question about pharo is welcome <[hidden email]>
Cc: Simon Denier <[hidden email]>
Subject: String insertion

What's the best (most elegant/efficient...) way to insert a string into another string at a given index?

Say I have the string 'Toto-Tata-Titi' and I want to build the string 'Toto-Tests-Tata-Titi'

I could think of the following:

| string sepIndex stream |
string := 'Toto-Tata-Titi'.
sepIndex := string indexOf: $-.
stream :=String new writeStream.
stream nextPutAll: (string copyFrom: 1 to: sepIndex).
stream nextPutAll: 'Tests'.
stream nextPutAll: (string copyFrom: sepIndex to: string size).
^ stream contents


Any suggestion?

--
Simon




--
 Simon




_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: String insertion

Alexandre Bergel
Something related are the macros, e.g., 'hello <1s>' expandMacrosWith: 'world'

Alexandre


On 27 Aug 2010, at 08:59, Simon Denier wrote:

>
>
> Begin forwarded message:
>
>> From: Simon Denier <[hidden email]>
>> Date: 19 août 2010 18:30:51 HAEC
>> To: A friendly place where any question about pharo is welcome <[hidden email]>
>> Cc: Simon Denier <[hidden email]>
>> Subject: String insertion
>>
>> What's the best (most elegant/efficient...) way to insert a string into another string at a given index?
>>
>> Say I have the string 'Toto-Tata-Titi' and I want to build the string 'Toto-Tests-Tata-Titi'
>>
>> I could think of the following:
>>
>> | string sepIndex stream |
>> string := 'Toto-Tata-Titi'.
>> sepIndex := string indexOf: $-.
>> stream :=String new writeStream.
>> stream nextPutAll: (string copyFrom: 1 to: sepIndex).
>> stream nextPutAll: 'Tests'.
>> stream nextPutAll: (string copyFrom: sepIndex to: string size).
>> ^ stream contents
>>
>>
>> Any suggestion?
>>
>> --
>> Simon
>>
>>
>>
>
> --
>  Simon
>
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev