Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 14:31, Salih Dincer wrote: > string splitz(string s) > { >import std.string : indexOf; >auto seekPos = s.indexOf('\0'); >return seekPos > 0 ? s[0..seekPos] : s; > } If you have multiple '\0' chars that you will continue looking for, how about the following? import std;

Re: to delete the '\0' characters

2022-09-22 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 22 September 2022 at 20:53:28 UTC, Salih Dincer wrote: ```d string splitz(string s) { import std.string : indexOf; size_t seekPos = s.indexOf('\0'); return s[0..seekPos]; } ``` I ignored the possibility of not finding '\0'. I'm fixing it now: ```d string splitz(string s) {

Re: to delete the '\0' characters

2022-09-22 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 22 September 2022 at 15:22:06 UTC, Ali Çehreli wrote: On 9/22/22 08:19, Ali Çehreli wrote: > ```d > string noZeroes(string s) > { > return s.byCodeUnit.filter!(c => c != '\0'); > } > ``` That won't compile; the return type must be 'auto'. Ali Thank you for all the valuable

Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 08:19, Ali Çehreli wrote: > string noZeroes(string s) > { > return s.byCodeUnit.filter!(c => c != '\0'); > } That won't compile; the return type must be 'auto'. Ali

Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 03:53, Salih Dincer wrote: > Is there a more accurate way to delete the '\0' characters at the end of > the string? I tried functions in this module: > https://dlang.org/phobos/std_string.html Just to remind, the following are always related as well because strings are arrays, which

Re: to delete the '\0' characters

2022-09-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer wrote: Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html ```d auto foo(string s) { string r; foreach(c; s) {

Re: to delete the '\0' characters

2022-09-22 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 22 September 2022 at 13:29:43 UTC, user1234 wrote: Two remarks: 1. The zero implicitly added to literals is not part of the string. for example s[$-1] will not give 0 unless you added it explictly to a literal 2. you code remove all the 0, not the one at the end. As it still

Re: to delete the '\0' characters

2022-09-22 Thread user1234 via Digitalmars-d-learn
On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer wrote: Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html ```d auto foo(string s) { string r; foreach(c; s) {

Re: to delete the '\0' characters

2022-09-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.09.22 13:14, ag0aep6g wrote: On 22.09.22 12:53, Salih Dincer wrote: [...] ```d auto foo(string s) {    string r;    foreach(c; s)    { if(c > 0) {    r ~= c; }    }    return r; } ``` [...] Here's a snippet that's a bit shorter than yours and doesn't copy the data:

Serial communication library

2022-09-22 Thread Imperatorn via Digitalmars-d-learn
Hi guys! What's the best/preferred library to use for serial communication (RS)? Thanks 

Re: to delete the '\0' characters

2022-09-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.09.22 12:53, Salih Dincer wrote: Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html ```d auto foo(string s) {   string r;   foreach(c; s)   {     if(c > 0)     {   r ~=

to delete the '\0' characters

2022-09-22 Thread Salih Dincer via Digitalmars-d-learn
Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html ```d auto foo(string s) { string r; foreach(c; s) { if(c > 0) { r ~= c; } } return r; } ``` SDB@79

Re: Poste some interesting vibe.d webpages

2022-09-22 Thread Alain De Vos via Digitalmars-d-learn
It's possible to remove the "@" annotation & use the default names of functions for the vibe framework, E.g, ``` final class WebChat { // GET / void get() { render!("index.dt", names); } void getEdit(string myid) { int id = myid.to!int; string