"strstr" D equivalent

2022-07-29 Thread pascal111 via Digitalmars-d-learn
Is there an equivalent in D for C function "strstr" that return the first occurrence of a given string within another string? https://en.cppreference.com/w/c/string/byte/strstr

Re: Build for i586

2022-07-29 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov wrote: I did a topic a [little earlier](https://forum.dlang.org/thread/hfzsnagofrnlmynyz...@forum.dlang.org) about compiling a compiler for processor Geode LX800. The bottom line is that I have a processor on which I want to compile

Re: "strstr" D equivalent

2022-07-29 Thread rassoc via Digitalmars-d-learn
On 7/29/22 13:23, pascal111 via Digitalmars-d-learn wrote: Is there an equivalent in D for C function "strstr" that return the first occurrence of a given string within another string? https://en.cppreference.com/w/c/string/byte/strstr You can use `find` from

Re: "strstr" D equivalent

2022-07-29 Thread pascal111 via Digitalmars-d-learn
On Friday, 29 July 2022 at 13:44:47 UTC, Salih Dincer wrote: **Short version:** ```d import std.string; import std.stdio; void find (string str, string substr) { if(auto pos = str.indexOf(substr)) { writefln("found the string '%s' in '%s' at position: %s", substr, str, pos);

Re: "strstr" D equivalent

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 July 2022 at 11:23:55 UTC, pascal111 wrote: Is there an equivalent in D for C function "strstr" that return the first occurrence of a given string within another string? https://en.cppreference.com/w/c/string/byte/strstr https://dlang.org/library/std/string/index_of.html I

Re: "strstr" D equivalent

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
**Short version:** ```d import std.string; import std.stdio; void find (string str, string substr) { if(auto pos = str.indexOf(substr)) { writefln("found the string '%s' in '%s' at position: %s", substr, str, pos); } else { writefln("the string '%s' was not found in

Re: "strstr" D equivalent

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 July 2022 at 14:14:54 UTC, pascal111 wrote: we won't find that there is a definition for it with just two parameters, so from where you got this new definition of this function?! This thread is about [UFCS](https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs).

Re: "strstr" D equivalent

2022-07-29 Thread Paul Backus via Digitalmars-d-learn
On Friday, 29 July 2022 at 14:14:54 UTC, pascal111 wrote: and if I'm right, with returning back to the definitions of "indexOf" @ https://dlang.org/phobos/std_string.html#.indexOf we won't find that there is a definition for it with just two parameters, so from where you got this new

Re: "strstr" D equivalent

2022-07-29 Thread pascal111 via Digitalmars-d-learn
On Friday, 29 July 2022 at 15:39:16 UTC, Salih Dincer wrote: On Friday, 29 July 2022 at 14:14:54 UTC, pascal111 wrote: we won't find that there is a definition for it with just two parameters, so from where you got this new definition of this function?! This thread is about

Is this a violation of const?

2022-07-29 Thread Andrey Zherikov via Digitalmars-d-learn
In the example below `func` changes its `const*` argument. Does this violates D's constness? ```d import std; struct S { string s; void delegate(string s) update; } void func(const S* s) { writeln(*s); s.update("func"); writeln(*s); } void main() { auto s =

A converting problem in using "among" with arrays

2022-07-29 Thread pascal111 via Digitalmars-d-learn
I next code, we have a data type problem "54.among(to!uint[10](y)).writeln;": module main; import std.stdio; import std.string; import std.conv; import dcollect; import std.math; import std.algorithm; int main(string[] args) { int[] x=[23, 34,-88, 54, -90, -34]; auto

Re: Is this a violation of const?

2022-07-29 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 29 July 2022 at 22:16:26 UTC, H. S. Teoh wrote: This totally makes sense. Thanks for explanation!

Re: A converting problem in using "among" with arrays

2022-07-29 Thread Andrey Zherikov via Digitalmars-d-learn
On Friday, 29 July 2022 at 22:09:47 UTC, pascal111 wrote: I next code, we have a data type problem "54.among(to!uint[10](y)).writeln;": module main; import std.stdio; import std.string; import std.conv; import dcollect; import std.math; import std.algorithm; int main(string[] args) {

Re: Is this a violation of const?

2022-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 29, 2022 at 09:56:20PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > In the example below `func` changes its `const*` argument. Does this > violates D's constness? > > ```d > import std; > > struct S > { > string s; > > void delegate(string s) update; > } > >

Re: A converting problem in using "among" with arrays

2022-07-29 Thread pascal111 via Digitalmars-d-learn
On Friday, 29 July 2022 at 22:12:54 UTC, Andrey Zherikov wrote: On Friday, 29 July 2022 at 22:09:47 UTC, pascal111 wrote: I next code, we have a data type problem "54.among(to!uint[10](y)).writeln;": module main; import std.stdio; import std.string; import std.conv; import dcollect; import

Re: A converting problem in using "among" with arrays

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 July 2022 at 22:09:47 UTC, pascal111 wrote: Error message: "hello.d|19|error: only one index allowed to index void|" ```d import std.stdio; void main() { int[] y = [-90, -88, -34]; /* ok but no compile y.to!uint[10] */ enum len = 10; y.length = len; int[len] v = y;

Re: A converting problem in using "among" with arrays

2022-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 29, 2022 at 10:32:11PM +, pascal111 via Digitalmars-d-learn wrote: [...] > I want searching for value 54 in array y "54.among(y).writeln;", but > it seems compiler complaints because the data type is "int[]", so I > tried to convert "y" to "uint[]". You're using the wrong

Re: A converting problem in using "among" with arrays

2022-07-29 Thread ryuukk_ via Digitalmars-d-learn
FYI, you can use the markdown code tag so your code is properly rendered when viewed from the forums (make sure to tick the "Enable Markdown", right next to Send) ``` ```D void my_function() { } ``` ``` it'll be rendered like this: ```D void my_function() { } ```

Re: Is this a violation of const?

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 July 2022 at 21:56:20 UTC, Andrey Zherikov wrote: In the example below `func` changes its `const*` argument. Does this violates D's constness? It's smart to use `delegate`, but `immutable` doesn't necessarily mean `const`. So if we use `const char`: ```d struct S {

Re: Is this a violation of const?

2022-07-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 July 2022 at 23:15:14 UTC, Salih Dincer wrote: It's smart to use `delegate`, but `immutable` doesn't necessarily mean `const`. So if we use `const char`: ```d struct S { char s; void delegate(char s) update; } ``` Pardon  I forgot the assert test, also writing const

Re: Does anyone here know how to create a Telegram bot in D?

2022-07-29 Thread AnimusPEXUS via Digitalmars-d-learn
On Saturday, 30 July 2022 at 04:06:28 UTC, Murilo wrote: Hi guys, I need to create a Telegram bot in D, does anyone here know how to do it? Is it possible to do it using arsd? https://core.telegram.org/bots/api The Bot API is an HTTP-based interface created for developers keen on building

Does anyone here know how to create a Telegram bot in D?

2022-07-29 Thread Murilo via Digitalmars-d-learn
Hi guys, I need to create a Telegram bot in D, does anyone here know how to do it? Is it possible to do it using arsd?

Re: Does anyone here know how to create a Telegram bot in D?

2022-07-29 Thread AnimusPEXUS via Digitalmars-d-learn
so basically you have to do http-client programming also there's some outdated tg packages in repo https://code.dlang.org/search?q=telegram