Bug 9702 – std.string.replace for single chars too?
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-12T10:53:25Z
Last change time
2018-11-15T07:20:38Z
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-03-12T10:53:25Z
The first form is accepted but the second form is rejected:
import std.string: replace;
void main() {
auto s1 = "hello".replace("h", "a"); // OK
auto s2 = "hello".replace('h', 'a'); // error
}
DMD 2.063alpha gives:
temp.d(4): Error: no overload matches for replace(E, R1, R2)(E[] subject, R1 from, R2 to) if (isDynamicArray!(E[]) && isForwardRange!(R1) && isForwardRange!(R2) && (hasLength!(R2) || isSomeString!(R2)))
Maybe it's worth supporting the second form too. The advantage is possibly a little more efficient algorithm, and more flexibility.