On Friday, 4 March 2022 at 21:20:20 UTC, Stanislav Blinov wrote:
On Friday, 4 March 2022 at 19:51:44 UTC, matheus wrote:
OK but there is another problem, I tested your version and
mine and there is a HUGE difference in speed:
string s, str = "4A0B1de!2C9~6";
Unless I did something wron
On Friday, 4 March 2022 at 20:38:11 UTC, ag0aep6g wrote:
...
The second version involves auto-decoding, which isn't actually
needed. You can work around it with
`str.byCodeUnit.filter!...`. On my machine, times become the
same then.
Typical output:
str: 401296
Tim(ms): 138
Tim(us): 138505
On Friday, 4 March 2022 at 20:33:08 UTC, H. S. Teoh wrote:
On Fri, Mar 04, 2022 at 07:51:44PM +, matheus via ...
I don't pay any attention to DMD when I'm doing anything
remotely performance-related. Its optimizer is known to be
suboptimal. :-P
Yes, in fact I usually do my coding/compilin
On Friday, 4 March 2022 at 19:51:44 UTC, matheus wrote:
OK but there is another problem, I tested your version and mine
and there is a HUGE difference in speed:
string s, str = "4A0B1de!2C9~6";
Unless I did something wrong (If anything please tell). By the
way on DMD was worse, it was
On Fri, Mar 04, 2022 at 08:38:11PM +, ag0aep6g via Digitalmars-d-learn
wrote:
[...]
> The second version involves auto-decoding, which isn't actually
> needed. You can work around it with `str.byCodeUnit.filter!...`. On my
> machine, times become the same then.
[...]
And this here is living p
On Friday, 4 March 2022 at 19:51:44 UTC, matheus wrote:
import std.datetime.stopwatch;
import std.stdio: write, writeln, writef, writefln;
import std;
void printStrTim(string s,StopWatch sw){
writeln("\nstr: ", s
,"\nTim(ms): ", sw.peek.total!"msecs"
,"\nTim(us): ", s
On Fri, Mar 04, 2022 at 07:51:44PM +, matheus via Digitalmars-d-learn wrote:
[...]
> for(j=0;j<1_000_000;++j){
> s="";
> s = str.filter!(ch => ch.isDigit).to!string;
This line allocates a new string for every single loop iteration. This
is generally not something you want to
On Thursday, 3 March 2022 at 23:46:49 UTC, H. S. Teoh wrote:
...
This version doesn't even allocate extra storage for the
filtered digits, since no storage is actually needed (each
digit is spooled directly to the output).
OK but there is another problem, I tested your version and mine
and t
On Thu, Mar 03, 2022 at 06:36:35PM -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 3/3/22 13:03, H. S. Teoh wrote:
>
> > string s = "blahblah123blehbleh456bluhbluh";
>
> > assert(result == 123456);
>
> I assumed it would generate separate integers 123 and 456. I started
> to impl
On Friday, 4 March 2022 at 10:34:29 UTC, Ali Çehreli wrote:
[...]
isMatched() and chunkOf() are not necessary at all. I wanted to
use readable names to fields of the elements of chunkBy instead
of the cryptic t[0] and t[1]:
It's delicious, only four lines:
```d
"1,2,3".chunkBy!(n => '0' <= n
On 3/4/22 01:53, Salih Dincer wrote:
> On Friday, 4 March 2022 at 07:55:18 UTC, forkit wrote:
>> If you get this question at an interview, please remember to first ask
>> whether it's ascii or unicode 😀
>
> ```d
> auto UTFsample = `
> 1 İş 100€, 1.568,38 Türk Lirası
> çarşıda eğri 1 çöp 4lınmaz!`;
On 3/3/22 04:14, BoQsc wrote:
> and if it contains integers, remove all the regular string characters.
Others assumed you wanted integer values but I think you want the digits
of the integers. It took me a while to realize that chunkBy can do that:
// Convenience functions to tuple members of
On Friday, 4 March 2022 at 07:55:18 UTC, forkit wrote:
If you get this question at an interview, please remember to
first ask whether it's ascii or unicode 😀
```d
auto UTFsample = `
1 İş 100€, 1.568,38 Türk Lirası
çarşıda eğri 1 çöp 4lınmaz!`;
UTFsample.splitNumbers.writeln; // [1, 100, 1, 568
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
I need to check if a string contains integers,
and if it contains integers, remove all the regular string
characters.
I've looked around and it seems using regex is the only closest
solution.
```
import std.stdio;
void main(string[] arg
On Friday, 4 March 2022 at 02:10:11 UTC, Salih Dincer wrote:
On Thursday, 3 March 2022 at 20:23:14 UTC, forkit wrote:
On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote:
I'm a simple man who uses D with the old C mentality:
[...]
```d
string s, str = "4A0B1de!2C9~6";
foreach(i;st
On Friday, 4 March 2022 at 02:36:35 UTC, Ali Çehreli wrote:
I assumed it would generate separate integers 123 and 456. I
started to implement a range with findSkip, findSplit, and
friends but failed. :/
I worked on it a little. I guess it's better that way. But I
didn't think about negati
On Friday, 4 March 2022 at 02:36:35 UTC, Ali Çehreli wrote:
On 3/3/22 13:03, H. S. Teoh wrote:
>string s = "blahblah123blehbleh456bluhbluh";
>assert(result == 123456);
I assumed it would generate separate integers 123 and 456. I
started to implement a range with findSkip, findSplit, a
On 3/3/22 13:03, H. S. Teoh wrote:
>string s = "blahblah123blehbleh456bluhbluh";
>assert(result == 123456);
I assumed it would generate separate integers 123 and 456. I started to
implement a range with findSkip, findSplit, and friends but failed. :/
Ali
On Thursday, 3 March 2022 at 20:23:14 UTC, forkit wrote:
On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote:
I'm a simple man who uses D with the old C mentality:
[...]
```d
string s, str = "4A0B1de!2C9~6";
foreach(i;str){
if(i < '0' || i > '9'){ continue; }
s ~= i
On Thu, Mar 03, 2022 at 10:54:39PM +, matheus via Digitalmars-d-learn wrote:
> On Thursday, 3 March 2022 at 21:03:40 UTC, H. S. Teoh wrote:
[...]
> > --
> > void main() {
> > string s = "blahblah123blehbleh456bluhbluh";
> > auto result = s.filter!(ch => ch.isDigit).to!int;
> > a
On Thursday, 3 March 2022 at 21:03:40 UTC, H. S. Teoh wrote:
...
--
void main() {
string s = "blahblah123blehbleh456bluhbluh";
auto result = s.filter!(ch => ch.isDigit).to!int;
assert(result == 123456);
}
--
Problem solved. Why write 6 lines when 3 will do?
Ju
On Thu, Mar 03, 2022 at 08:23:14PM +, forkit via Digitalmars-d-learn wrote:
> On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote:
> >
> > I'm a simple man who uses D with the old C mentality:
> >
> > import std.stdio;
> >
> > void main(){
> > string s, str = "4A0B1de!2C9~6";
> >
On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote:
I'm a simple man who uses D with the old C mentality:
import std.stdio;
void main(){
string s, str = "4A0B1de!2C9~6";
foreach(i;str){
if(i < '0' || i > '9'){ continue; }
s ~= i;
}
writeln("Result: ", s);
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
I've looked around and it seems using regex is the only closest
solution.
I'm a simple man who uses D with the old C mentality:
import std.stdio;
void main(){
string s, str = "4A0B1de!2C9~6";
foreach(i;str){
if(i < '0' ||
On Thursday, 3 March 2022 at 13:55:47 UTC, BoQsc wrote:
On Thursday, 3 March 2022 at 13:25:32 UTC, Stanislav Blinov
wrote:
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
I need to check if a string contains integers,
and if it contains integers, remove all the regular string
characte
On Thursday, 3 March 2022 at 13:25:32 UTC, Stanislav Blinov wrote:
auto filtered = () {
auto r = args[1].find!isNumber; // check if a
string contains integers
```
**When using ```find!isNumber```:**
```
0123456789
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnop
On Thursday, 3 March 2022 at 13:25:32 UTC, Stanislav Blinov wrote:
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
I need to check if a string contains integers,
and if it contains integers, remove all the regular string
characters.
I've looked around and it seems using regex is the on
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:
I need to check if a string contains integers,
and if it contains integers, remove all the regular string
characters.
I've looked around and it seems using regex is the only closest
solution.
```d
import std.stdio;
import std.algorithm
28 matches
Mail list logo