Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 24, 2015 A better way than foreach with this? | ||||
---|---|---|---|---|
| ||||
auto names = "Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf " "Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe " "Pe Final_Tsadi Tsadi Qof Resh Shin Tav".split; foreach (ref name; names) name = replace(name, "_", " "); |
August 24, 2015 Re: A better way than foreach with this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | On 2015-08-24 07:58, Joel wrote: > auto names = > "Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf " > "Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe " > "Pe Final_Tsadi Tsadi Qof Resh Shin Tav".split; > > foreach (ref name; names) > name = replace(name, "_", " "); > Why not call the "replace" function directly on "names"? -- /Jacob Carlborg |
August 24, 2015 Re: A better way than foreach with this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | try:
auto names1 = names.map!( a => replace(a, "_"," "));
...not sure how to do it in-place though.
Joel wrote:
> auto names =
> "Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf "
> "Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe "
> "Pe Final_Tsadi Tsadi Qof Resh Shin Tav".split;
>
> foreach (ref name; names)
> name = replace(name, "_", " ");
>
|
August 24, 2015 Re: A better way than foreach with this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Monday, 24 August 2015 at 06:13:50 UTC, Jacob Carlborg wrote:
> On 2015-08-24 07:58, Joel wrote:
>> auto names =
>> "Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf "
>> "Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe "
>> "Pe Final_Tsadi Tsadi Qof Resh Shin Tav".split;
>>
>> foreach (ref name; names)
>> name = replace(name, "_", " ");
>>
>
> Why not call the "replace" function directly on "names"?
They would split wrong.
|
August 24, 2015 Re: A better way than foreach with this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ted | On Monday, 24 August 2015 at 06:17:02 UTC, ted wrote:
> try:
> auto names1 = names.map!( a => replace(a, "_"," "));
>
> ...not sure how to do it in-place though.
>
> Joel wrote:
>
>> auto names =
>> "Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf "
>> "Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe "
>> "Pe Final_Tsadi Tsadi Qof Resh Shin Tav".split;
>>
>> foreach (ref name; names)
>> name = replace(name, "_", " ");
Thanks, worked it out, (though has 'array'):
names = names.map!( a => replace(a, "_"," ")).array;
|
Copyright © 1999-2021 by the D Language Foundation