How to add a character literal to a string without ~ operator?

2024-04-04 Thread BoQsc via Digitalmars-d-learn
I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm not here to discuss that. I'm looking for a function inside standard library. The function should be straightforward, up to

Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
Matches function declarations and captures function names from `.d` Source Code file **regexcapture.d** ``` import std.stdio : writeln; import std.regex : matchAll, regex; import std.file : read; void main(){ string input = cast(string)read("sourcecode.d"); foreach(match;

Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
On Monday, 11 December 2023 at 05:18:45 UTC, thinkunix wrote: BoQsc via Digitalmars-d-learn wrote: This is something I've searched on the forum and couldn't find exact answer. TLDR: `r"^."` is matching the very first two character in the `input` string. Don't you need two dots to

Reading .txt File into String and Matching with RegEx

2023-12-10 Thread BoQsc via Digitalmars-d-learn
This is something I've searched on the forum and couldn't find exact answer. TLDR: `r"^."` is matching the very first two character in the `input` string. **matchtest.d** ``` import std.stdio : writeln; import std.regex : matchAll; import std.file : read; void main(){ string input

Re: D Snippet: Reading a file to standard output on Windows Operating System. (FileScan.d)

2023-12-09 Thread BoQsc via Digitalmars-d-learn
`switch` statement to match a text line While outputing to the standard stream, it is also possible to use `switch` statement to **match a text line to a text line in a file.** I personally think it improve readability and maintainability in some applications. ``` import std; void

Re: D Snippet: Reading a file to standard output on Windows Operating System. (FileScan.d)

2023-12-08 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 6 December 2023 at 14:56:50 UTC, BoQsc wrote: As of recent observation the `line` in the previous implementation seem to recognise **\r** as default terminator. Making `writeln("|" ~ line ~ "|");` not possible. By correcting terminator and disabling it on `byLine` function it

Re: D Snippet: Reading a file to standard output on Windows Operating System. (FileScan.d)

2023-12-06 Thread BoQsc via Digitalmars-d-learn
As of recent observation the `line` in the previous implementation seem to recognise **\r** as default terminator. Making `writeln("|" ~ line ~ "|");` not possible. By correcting terminator and disabling it on `byLine` function it is possible to achieve following output to standard stream:

D Phobos Library Documentation: What is the Internal API for?

2023-11-27 Thread BoQsc via Digitalmars-d-learn
This is pretty basic question. If you open [D Library Reference](https://dlang.org/phobos/index.html) you are bound to see the **Internal API** section in the table of content. What is the **Internal API** (internal.core, dmd, rt) for and when, how and where to use it?

D: Convert/parse uint integer to string. (@nogc)

2023-11-24 Thread BoQsc via Digitalmars-d-learn
I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to produce a `string` value out of `uint` value. How to convert

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
On Thursday, 23 November 2023 at 20:00:31 UTC, H. S. Teoh wrote: On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using

D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using Win32 - Windows Operating System API. * Empty pointer variables are used by functions to return information after the function is done. My

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-18 Thread BoQsc via Digitalmars-d-learn
Latest iteration on this thread. Limitations: * pipes through two programs. * very verbose, hard to use. ``` import std; import std.process; version (Windows) { enum Find = "find"; } version (Posix) { enum Find = "grep"; } void pipeTo(Pipe p, string nextprogram){

D: How to check if a function is chained? a().b().c();

2023-11-17 Thread BoQsc via Digitalmars-d-learn
Let's say we have a chain of functions. ``` a().b().c(); ``` I would like to have a behaviour in `a()` that would check if there is `b()` or `c()` chained to it. If `a();`is not chained: do a `writeln("You forgot to chain this function!");` A function that executes a program For me

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-12 Thread BoQsc via Digitalmars-d-learn
To make this thread more complete, here is the final version. ``` import std.stdio; import std.process; version (Windows) { enum Find = "find"; } version (Posix) { enum Find = "grep"; } int main (string [] args) { auto p1 = pipe; auto p2 = pipe; auto pid1 = spawnShell("echo

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-12 Thread BoQsc via Digitalmars-d-learn
Using `spawnShell` it all seem to work. However the question of why `spawnProcess(["find", "string to find"]` is not working and produces error is still unresolved. Works with `spawnShell`: ``` import std.stdio; import std.process; version (Windows) { enum Find = "find"; } version (Posix) {

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-12 Thread BoQsc via Digitalmars-d-learn
On Windows: While trying to use `spawnshell` I discovered that I can not use any alphabetical letters inside the `spawnProcess([Find, "Hello"])` it all works when they are numerical `[Find, "6515"]`. As of recent testing `[Find, "df123"]` also is acceptable, but not when letter is on the

D: How would one make a shared dynamically linked D library?

2023-11-08 Thread BoQsc via Digitalmars-d-learn
I would like to export some functionality as external shared dynamically linked D library. Is it possible to do that in D Language and what are limitations? A simple `writeln` example would be great. What I expect is an executable that uses functions, variables, classes, modules from

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-06 Thread BoQsc via Digitalmars-d-learn
To test the behaviour of static library. **program.d** ``` module program; import std.stdio; import library; void main(string[] args) { writeln("func(3) = ", library.func(3)); } ``` **Command Line:** ``` dmd "./program.d" "./builds/library.di" "./builds/library.lib" -ofProgram.exe

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-06 Thread BoQsc via Digitalmars-d-learn
In summary this is what it all combined could look like. **dub.sdl** ``` name "dheaders" description "generates .di header file for a static library." authors "public domain" copyright "Public Domain. No rights reserved." license "public domain" configuration "staticLibrary" { dflags

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-06 Thread BoQsc via Digitalmars-d-learn
Update: To allow only `.di` (D Header) output: Instead of configuration, it would be more correct to make a new `build type`. ``` buildType "headerFileOnly" { extraDependencyFiles "$PACKAGE_DIR/builds/library.di" dflags "-Hf=$PACKAGE_DIR/builds/library.di" dflags

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-05 Thread BoQsc via Digitalmars-d-learn
Configuration to generate only `.di` (D Header file) ``` name "dheaders" description "generates .di header file for a static library." authors "public domain" copyright "Public Domain. No rights reserved." license "public domain" configuration "staticLibrary" { dflags

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-05 Thread BoQsc via Digitalmars-d-learn
**Conclusive observation:** This can be resolved by informing `dub` of `extraDependencyFiles` to rebuild itself. `library.di` non-existance simply does not trigger rebuild of the package and instead only `library.lib` is being copied from the `cache` folder into `build` folder. Leaving

Re: DUB: Sometimes generates .di file and sometimes do not.

2023-11-05 Thread BoQsc via Digitalmars-d-learn
On Sunday, 5 November 2023 at 10:54:35 UTC, Imperatorn wrote: On Sunday, 5 November 2023 at 10:53:33 UTC, BoQsc wrote: I would like to know how to solve this problem with `dub`. **dub.sdl** ``` name "dheaders" description "generates .di header file for a static library." authors "public

DUB: Sometimes generates .di file and sometimes do not.

2023-11-05 Thread BoQsc via Digitalmars-d-learn
I would like to know how to solve this problem with `dub`. **dub.sdl** ``` name "dheaders" description "generates .di header file for a static library." authors "public domain" copyright "Public Domain. No rights reserved." license "public domain" configuration "staticLibrary" { dflags

Re: DUB: Is it possible to set release as a default build for a dub package?

2023-11-04 Thread BoQsc via Digitalmars-d-learn
On Friday, 3 November 2023 at 21:57:57 UTC, Andrey Zherikov wrote: On Friday, 3 November 2023 at 19:21:42 UTC, BoQsc wrote: However I would want to try to enforce this behaviour from the `dub.json` or `dub.sdl` file. IMHO this is not something that should be enforced from package build

DUB: Is it possible to set release as a default build for a dub package?

2023-11-03 Thread BoQsc via Digitalmars-d-learn
While using `dub`, you might notice that after running `dub` or `dub run` command you will end up with notice: ``` Starting Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. ``` Example output: ``` C:\Users\Windows10\Documents\Dlang winsock\datatypes>dub

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread BoQsc via Digitalmars-d-learn
Well the whole thread is about importing `package.d` while being inside package to provide runnable working example which contains debug information of the package. Sidenote: This is essentially useful when distributing over many machines/platforms via `dub` package manager. You would want

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread BoQsc via Digitalmars-d-learn
On Thursday, 2 November 2023 at 11:32:40 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 11:12:58 UTC, BoQsc wrote: On Thursday, 2 November 2023 at 10:53:12 UTC, Arafel wrote: On 02.11.23 11:45, BoQsc wrote: Edit incorrect link to example: [Extensive run.dlang.io

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread BoQsc via Digitalmars-d-learn
On Thursday, 2 November 2023 at 10:53:12 UTC, Arafel wrote: On 02.11.23 11:45, BoQsc wrote: Edit incorrect link to example: [Extensive run.dlang.io example](https://run.dlang.io/is/f3jURn) Correct link: https://run.dlang.io/is/Zbrn75 ``` --- waffles/program.d import waffles; ``` See

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread BoQsc via Digitalmars-d-learn
Edit incorrect link to example: [Extensive run.dlang.io example](https://run.dlang.io/is/f3jURn) Correct link: https://run.dlang.io/is/Zbrn75

Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread BoQsc via Digitalmars-d-learn
![](https://i.imgur.com/829CzOS.png) Source File **package.d** is a [package module][1] which contains import statements to import other modules. How would one import a **package.d** module when [**keyword "package"**][2] is preventing that? [1]:

Weird RDMD error when trying to import source file from subfolder.

2023-11-01 Thread BoQsc via Digitalmars-d-learn
I'm unable to import a `.d` source file from a subfolder. Now this happens only with `rdmd`. The `dmd -i -run` works perfectly. I'm currently on Windows 10 operating system. **./testimport.d**: ``` import std; import waffle.next; void main(){ writeln("test", testing); } ```

Re: Define a new custom operator in D Language.

2023-10-02 Thread BoQsc via Digitalmars-d-learn
On Monday, 2 October 2023 at 18:39:41 UTC, Imperatorn wrote: On Monday, 2 October 2023 at 18:34:13 UTC, BoQsc wrote: Here is my issue: I've found a formula on Wikipedia. It's called **Hashing by division**. ![](https://i.imgur.com/UJPAWIW.png) As you can see it uses **mod** keyword to achieve

Re: Associate information with a pointer address.

2023-10-01 Thread BoQsc via Digitalmars-d-learn
The package dependency `emsi_containers` that can be found in https://code.dlang.org/packages/emsi_containers might be a viable way to resolve the problem. ``` /+dub.sdl: dependency "emsi_containers" version="~>0.7" +/ import std; void main(string[] args) @nogc { import containers;

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
After being very happy about associative arrays of D Language, I encountered that they are not `@nogc`friendly. Unsure if I should wait for D language to support it, or do I need to rethink everything. Error ``` onlineapp.d(20): Error: assigning an associative array element in `@nogc`

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
Out of scope access to a variable using stored pointer address, demonstration. ``` import std; void outofcontext() { writeln("Hello D ", associative); foreach (pointeraddress, information; associative) { writeln(*cast(string*)pointeraddress); } } static string[void* ]

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
Bonus: Store hexadecimal literals in associative array of pointer addresses. ``` import std; void main() { string[void *] associative; // Store Hexadecimal as pointer address in associative array associative[cast(void *)0x7FFCD332CD60] = "someinformation"; // Store

Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
For some reason I thought this was something I wanted to achieve and share. ``` import std; void main() { string variable; void * pointeraddress = string[void *] associative; associative[pointeraddress] = "someinformation"; writeln("Hello D ", pointeraddress);

Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-18 Thread BoQsc via Digitalmars-d-learn
Note that this doesn't work in gdc. The templated version is actually more akin to what C does. Yeah it does not seem to work in gdc when tested using https://d.godbolt.org/ The errors produced: ``` :11:12: error: none of the overloads of template 'core.stdc.stdarg.va_arg' are callable

How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-14 Thread BoQsc via Digitalmars-d-learn
https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more verbose? `va_arg!(int)(_argptr);` is taken from an example in:

Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread BoQsc via Digitalmars-d-learn
https://docarchives.dlang.io/v2.073.0/spec/struct.html#struct-literal I would like to set function's default struct for a function in a way that it would be visible for the reader to see what options are set. Something like `Options option = {silenceErrors: false}` Here is an example of

Dlang Forum: How to Subscribe to the "Replies to your posts"

2023-09-10 Thread BoQsc via Digitalmars-d-learn
Some people might not know that it is possible to subscribe and get notifications about replies to your forum posts via email. 1. Open main forum page and click **"new replies"** link ![img1](https://i.imgur.com/HwhDCKO.png) --- 2. Scroll down to the bottom of the page

Is sizeof() available in D language?

2023-09-04 Thread BoQsc via Digitalmars-d-learn
I've seen everyone using **datatype**`.sizeof` property. https://dlang.org/spec/property.html#sizeof It's great, but I wonder if it differ in any way from the standard C function `sizeof()`. https://www.geeksforgeeks.org/sizeof-operator-c/ https://en.cppreference.com/w/cpp/language/sizeof

Re: Windows API: GetUserName: Retrieve the name of the user associated with the current thread.

2023-08-20 Thread BoQsc via Digitalmars-d-learn
Update: GetUserName by print to stdout Main function has been updated with `string[] args` and a new feature: ``` if (args.length > 1 && args[1] == "print") { write(username); } ``` Usage: `WindowsGetUserName.exe print` Demonstration

Windows API: GetUserName: Retrieve the name of the user associated with the current thread.

2023-08-19 Thread BoQsc via Digitalmars-d-learn
I'm sharing some code here. **It's not completely tested and might contain serious mistakes, repetitions, bad style and readabilty. But it seems to work.** Critique, improvements and feedback might help. Demonstration This code retrieves username of the current windows user using

Windows API: lld-link: error: undefined symbol: GetUserNameA

2023-08-19 Thread BoQsc via Digitalmars-d-learn
Today I've tried to use Windows API once again and encountered very time consuming case. It's been a long time since the last time I used Windows API. This time I've had an idea that it would be interesting to get thread associated username using Windows API. So after some time while trying

DMD: Versioning compilation: generate Identifier for each compilation and writeln it.

2023-08-19 Thread BoQsc via Digitalmars-d-learn
I would like to display some identifier that is set after compilation and remains unchanged. This is to recognise and check if two binaries belong to the same compilation or it is a different compilation. I would place it into **version** command of my program. This is what I have now.

Which D compiler is the most maintained and future-proof? [DMD GDC and LDC]

2023-07-24 Thread BoQsc via Digitalmars-d-learn
There are three compilers present in the Dlang website: DMD GDC and LDC

[Win32 API] MessageBox Example without MSVCR120.dll dependency

2022-12-25 Thread BoQsc via Digitalmars-d-learn
This is a working Hello World example without dependency on Microsoft C Runtime Library, I couldn't find anything by searching around the forums or search engines, so I'm posting it here. Please provide improvements if you feel like something is missing or incorrect. **How to Compile:** `dmd

Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment

2022-09-05 Thread BoQsc via Digitalmars-d-learn
On Sunday, 4 September 2022 at 22:05:24 UTC, ShadoLight wrote: On Sunday, 4 September 2022 at 15:16:47 UTC, BoQsc wrote: **Folder structure** .\msvcr120.dll .\folder1\HelloWorld.exe .\folder2\HelloWorld.exe You don't need to do this. msvcr120.dll is already shipped with the DMD compiler

How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment

2022-09-04 Thread BoQsc via Digitalmars-d-learn
![HelloWorld](https://i.imgur.com/5BjVIU9.png) **Folder structure** .\msvcr120.dll .\folder1\HelloWorld.exe .\folder2\HelloWorld.exe Basic binaries produced by DMD.exe compiler require Microsoft Compiler Runtime DLL As you might know that a basic D Language example `HelloWorld.exe`

Importing module from the perspective of submodule.

2022-07-02 Thread BoQsc via Digitalmars-d-learn
Is it possible to import module that is not in the module's current directory's folder or subfolders? For example: I want to import `somemodule2.d` and `somemodule3.d` into a **`somemodule.d`** **.\somefolder\somemodule.d** .\somemodule2.d .\someotherfolder\somemodule3.d

What exact debugging information is added to the binary and how to parse it all?

2022-05-13 Thread BoQsc via Digitalmars-d-learn
Haven't used debuggers or debugged a lot just yet, but I've had this question in my mind and I'd like to inspect some debugging information manually. Are there some kind of documentation or specification and are there a lot of information that is hidden in a an average "debuggable" binary?

Re: DUB issues

2022-04-18 Thread BoQsc via Digitalmars-d-learn
On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Hey All, For some reason I cannot reset my password to get into dub (https://code.dlang.org/), after trying I never receive the email to reset my password. I was unsure at first if I had signed up at all, but trying to make a

Collect the arguments of all the function calls at a compile time in the whole program.

2022-04-15 Thread BoQsc via Digitalmars-d-learn
Let's say I have this example program. I want to get the arguments of all the `some_function();` in the whole program. **Even if the scope of the function call is never executed.** (Ex. due to IF statement being negative.) I tried to use `__traits` but it seems to not gather any information

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
On Thursday, 7 April 2022 at 12:51:26 UTC, Stanislav Blinov wrote: On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: wchar_t* clang_string = cast(wchar_t *)"AA"; You're witnessing undefined behavior. "AA" is a string literal and is stored in the data

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
On Thursday, 7 April 2022 at 11:03:39 UTC, Tejas wrote: On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: Here I try to concatenate three character strings using `wcsncat()`. [...] Maybe try using `wstring` instead of string? Also use the `w` postfix ```d wstring dlang_string =

A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
Here I try to concatenate three character strings using `wcsncat()`. `clang_string` AA `dlang_string` BBB `winpointer_to_string` CC ``` import std.stdio; @system void main(){ import std.utf: toUTF16z, toUTF16; import

How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread BoQsc via Digitalmars-d-learn
I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string that is to be combined. I'd like to take a look at strings, analyse them manually and see if any of them end up terminated or not. Please provide any relevant examples of how you

Re: Check if Key exists in Associative Array using D language.

2022-04-05 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 5 April 2022 at 11:53:19 UTC, Dennis wrote: On Tuesday, 5 April 2022 at 11:26:27 UTC, BoQsc wrote: I'd like to know if there is similar function: that can check if a **key** inside a [Associative Array][2] can be found. You can use the `in` operator for that:

Check if Key exists in Associative Array using D language.

2022-04-05 Thread BoQsc via Digitalmars-d-learn
I've found [std.algorithm: canFind][1] to be useful on a **regular arrays**. I'd like to know if there is similar function: that can check if a **key** inside a [Associative Array][2] can be found. [1]:https://dlang.org/phobos/std_algorithm_searching.html#.canFind

Re: How to exclude function from being imported in D language?

2022-03-09 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 8 March 2022 at 22:28:27 UTC, bauss wrote: On Tuesday, 8 March 2022 at 20:12:40 UTC, BoQsc wrote: I think D Language needs and lacks conditional compilation condition and attribute of "exclude". The exclude keyword or code block in the exclude, would be made sure to not be

Re: How to exclude function from being imported in D language?

2022-03-08 Thread BoQsc via Digitalmars-d-learn
I think D Language needs and lacks conditional compilation condition and attribute of "exclude". The exclude keyword or code block in the exclude, would be made sure to not be imported by any means. Now it seems all to be only workarounds.

How to exclude function from being imported in D language?

2022-03-08 Thread BoQsc via Digitalmars-d-learn
Premise: In D language, only one main(){} function can exist in a program. Having two `main()` functions throws an error. Let's say I want to use some functionality of another program, but it has a `main(){}` function. How can I import and use functions without importing the `main(){}`

Re: SendMessageTimeoutW requires casting string to uint?

2022-03-05 Thread BoQsc via Digitalmars-d-learn
Update: 2022-03-04 ChangeLog: * Fixed Typos * Added Switch Statement for Command Line Interface Arguments * Added Switch Statement for Policy, intl, Environment * Added Switch Statement for Error handling: Exit status, Error level * Increased window "timeout" from 1 to 1000

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-03 Thread BoQsc via Digitalmars-d-learn
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

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

2022-03-03 Thread BoQsc via Digitalmars-d-learn
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[] args){ if (args.length > 1){

How to convert a string command line argument to an int?

2022-03-02 Thread BoQsc via Digitalmars-d-learn
I tried to use `std.conv.parse(args[2])`, ``` import std.stdio; import std.conv; void main(string[] args){ if (args.length > 1) { writeln(broadcastSettingChange(args[1])); if (args.length == 2) { // TODO: second argument needs parse to

Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread BoQsc via Digitalmars-d-learn
`bool nextArgumentDoesNotReachEndOfArray = i + 1 < args.length;` How can I declare it out of scope and reuse it in any scope that has `i` and `args.length` declared?

Re: Is this Windows Win32 fileapi.h header accessible in D language?

2022-02-08 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 18:21:46 UTC, duser wrote: On Tuesday, 8 February 2022 at 16:10:19 UTC, BoQsc wrote: Unsure where to start, so I decided to ask here how to get use of this win32 header. https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ the specific module containing

Is this Windows Win32 fileapi.h header accessible in D language?

2022-02-08 Thread BoQsc via Digitalmars-d-learn
Unsure where to start, so I decided to ask here how to get use of this win32 header. https://docs.microsoft.com/en-us/windows/win32/api/fileapi/

Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote: On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: Let's say I want to skip characters and build a new string. The string example to loop/iterate: ``` import std.stdio; void main() { string a="abc;def;ab"; } ``` The

Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 12:49:39 UTC, Adam D Ruppe wrote: On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: The string example to loop/iterate: foreach(ch; a) { } does the individual chars of the string you can also foreach(dchar ch; a) { } to decode the utf 8 Thanks

Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 11:35:39 UTC, Biotronic wrote: On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: Let's say I want to skip characters and build a new string. The string example to loop/iterate: ``` import std.stdio; void main() { string a="abc;def;ab"; } ```

How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn
Let's say I want to skip characters and build a new string. The string example to loop/iterate: ``` import std.stdio; void main() { string a="abc;def;ab"; } ``` The character I want to skip: `;` Expected result: ``` abcdefab ```

Re: How to use std.windows.registry, there are no documentations.

2021-11-30 Thread BoQsc via Digitalmars-d-learn
On Saturday, 27 November 2021 at 19:59:24 UTC, Imperatorn wrote: On Wednesday, 24 November 2021 at 12:07:44 UTC, BoQsc wrote: On Thursday, 11 July 2019 at 08:53:35 UTC, BoQsc wrote: [...] ``` import std.stdio; import std.windows.registry; [...] You could add some examples to the

Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 20:29:36 UTC, Imperatorn wrote: On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote: On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe wrote: On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote: The many times I tried this pragma, it

Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
Since the **linkerDirective pragma** is not supported for OMF object file. Linker directives are only supported for MS-COFF output. https://dlang.org/spec/pragma.html#linkerDirective I doubt that this thread is completely resolved.

Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote: [...] **The obvious problem now is:** How can you compile without specifying the flags. With plain dmd. It probably has to do something with the default target of dmd (`-m32`) generating **OMF object file**.

Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe wrote: On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote: The many times I tried this pragma, it did not even get recognised as pragma at all. You need to use `dmd -m32mscoff` or `dmd -m64`. Plain `dmd` won't work. If

Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 17:14:42 UTC, Adam D Ruppe wrote: On Wednesday, 24 November 2021 at 17:06:21 UTC, BoQsc wrote: **The question:** Is there a way to include the `.def` file instructions inside `.d` file, so that there won't be a need for additional `.def` file when compiling.

Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
I'm not sure if I have sucessfully achieved something like this before or is it even possible right now, but there is a sample file that comes with DMD compiler: `D\dmd2\samples\d\winsamp.d` **The problem:** `winsamp.d` have to be compiled with `.def` file. ``` /+ Compile with: + dmd winsamp

How to use std.windows.registry, there are no documentations.

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Thursday, 11 July 2019 at 08:53:35 UTC, BoQsc wrote: https://dlang.org/phobos/std_windows_registry.html https://github.com/dlang/phobos/blob/master/std/windows/registry.d Can someone provide some examples on how to: set, change, receive something from the Windows registry using Phobos

How to make a new dub subpackage? [Answered]

2021-11-20 Thread BoQsc via Digitalmars-d-learn
Note: It is not possible to make subpackage inside subpackage. To make a subpackage with dub; follow these general guidelines. **General guidelines** 1. Create a new folder. 2. Open the folder. 3. Initialise a new package. (`dub init`) 4. Open `dub.json` file * Append this: ```

Re: How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn
On Friday, 19 November 2021 at 18:01:57 UTC, Adam D Ruppe wrote: On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote: Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the

How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn
Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the program should stop.

Re: Find a char among string (string.findAmong.char)

2021-07-07 Thread BoQsc via Digitalmars-d-learn
I think nested foreach loops are more readable. ``` import std; void main() { alias alphabet = letters; char[26] letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',

Re: Find a char among string (string.findAmong.char)

2021-07-06 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 15:48:35 UTC, rassoc wrote: You can also do: ```d import std; void main() { // https://dlang.org/phobos/std_ascii.html#.lowercase "Book.".filter!(c => lowercase.canFind(c)) .each!(c => writeln(c, " found")); // Output: // o found //

Re: Find a char among string (string.findAmong.char)

2021-07-06 Thread BoQsc via Digitalmars-d-learn
On Monday, 5 July 2021 at 19:48:13 UTC, jfondren wrote: On Monday, 5 July 2021 at 19:34:14 UTC, BoQsc wrote: But I really don't like how it looks less readable and makes less sense on first look. `if (([letter].findAmong(alphabet)).length)` I'd like to use some method on the `letter` instead

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn
On Monday, 5 July 2021 at 19:25:23 UTC, jfondren wrote: On Monday, 5 July 2021 at 19:19:19 UTC, BoQsc wrote: If I use `[letter].findAmong(alphabet)` in my code, it considers a dot (.) punctuation character as a letter. You can see it here: https://run.dlang.io/is/YWmaXU It returns a

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn
On Monday, 5 July 2021 at 18:59:09 UTC, jfondren wrote: On Monday, 5 July 2021 at 18:53:27 UTC, jfondren wrote: If you replace the findAmong call with `[letter].findAmong(alphabet)`, this works. Consider: ```d import std; void main() { import std.ascii : alphabet = letters;

Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn
I get an error when I try to find that letter is among alphabet. onlineapp.d(13): Error: template `std.algorithm.searching.findAmong` cannot deduce function from argument types `!()(immutable(char), immutable(string))`, candidates are:

Download a file into array (using std.net.curl.download)

2021-07-05 Thread BoQsc via Digitalmars-d-learn
Let's say I can't store information into files. Is it possible to download a file into an array. This is what I have now. It saves a download into a file named: file.txt import std; import std.net.curl; void main() { writeln("Hello D");

Re: Is there an alias for standard libraries to use in import statement?

2021-07-04 Thread BoQsc via Digitalmars-d-learn
On Sunday, 4 July 2021 at 08:50:54 UTC, Mike Parker wrote: You can use named imports, but then you have to use the name as a namespace: ``` import system = std; void main() { system.writeln("Hello D"); } ``` These were the examples that might feel more readable and natural than

Is there an alias for standard libraries to use in import statement?

2021-07-04 Thread BoQsc via Digitalmars-d-learn
I just started with a fresh look at the D language and would like to be able to rewrite this code: import std; void main() { writeln("Hello D"); } Into more readable standard library name: import system; void main() { writeln("Hello D"); } Or into this import library.standard;

Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote: On Wednesday, 3 June 2020 at 19:53:03 UTC, BoQsc wrote: Removing the last element of the string got it resolved. Might not be the best way and adding additional check for carriage return before removing the element would be better, so this

Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
Removing the last element of the string got it resolved. Might not be the best way and adding additional check for carriage return before removing the element would be better, so this is only initial proof. Improved example with the above comments resolved. testingGround.d import

Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 18:49:38 UTC, ttk wrote: On Wednesday, 3 June 2020 at 18:23:51 UTC, BoQsc wrote: Here you can see ". hahahahahahaha" and "nononono" and even lineNumber is being merged into the same position. Why is this happening and can this be simply resolved? Your string in

writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd testingGround.d 0. The quick brown fox jumps over the lazy dog nonononoahahahaha Sphinx of black quartz, judge my vow. 2. # How vexingly quick daft zebras jump! 3. # The five boxing wizards jump quickly 4. # Maecenas consectetur risus a

  1   2   >