Re: How to use ImportC?

2022-03-04 Thread MoonlightSentinel via Digitalmars-d-learn
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly

Re: How to work with hashmap from memutils properly?

2022-03-04 Thread Sergey via Digitalmars-d-learn
On Wednesday, 16 February 2022 at 13:37:28 UTC, ikod wrote: On Wednesday, 16 February 2022 at 10:31:38 UTC, Siarhei Siamashka wrote: On Friday, 11 February 2022 at 19:04:41 UTC, Sergey wrote: Is this an attempt to implement a high performance solution for the Benchmarks Game's LRU problem in D

Re: How to use ImportC?

2022-03-04 Thread bachmeier via Digitalmars-d-learn
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote: On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread matheus via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread ag0aep6g via Digitalmars-d-learn
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): ",

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Stanislav Blinov via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread matheus via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread matheus via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread matheus via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread BoQsc via Digitalmars-d-learn
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[]

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread forkit via Digitalmars-d-learn
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";

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Salih Dincer via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Salih Dincer via Digitalmars-d-learn
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,

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread H. S. Teoh via Digitalmars-d-learn
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