Is there a similar library to FreeMarker like in Java

2020-11-11 Thread Namal via Digitalmars-d-learn
Hello, I want to do a small project but I need a text replacement tool/lib like Apache's FreeMarker. Is there something similar for D? Thx

Re: preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:48:17 UTC, mipri wrote: On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } }

preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++)

preset counter variable in a for loop --> 'has no effect' Error

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++)

Re: Question about the $ sign in arrays and strings

2020-02-18 Thread Namal via Digitalmars-d-learn
oooh... I used str = std.readln(); to get my string and there must have been some other sign, line break or whitespace or something at the end :( Now I understand it, thx

Question about the $ sign in arrays and strings

2020-02-18 Thread Namal via Digitalmars-d-learn
Hello, I wanted to remove the lastchar in a string and figured that you can do that wit str = str[0..$-2]; but why is str = str[0..$] and str=str[0..$-1] the same ?

How to remove whitespace from a string

2020-01-16 Thread Namal via Digitalmars-d-learn
Hello, what is the way to remove whitespace from a string (not only at the beginning and end)..

User input

2017-11-08 Thread Namal via Digitalmars-d-learn
Is there any other way to do a simple user input into integer variables without using std.conv?

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote: import std.string: representation, assumeUTF; import std.algorithm: sort; auto bytes = line.representation.dup; bytes.sort; auto result = bytes.assumeUTF; // result is now char[] Why does it have to be char[]? auto

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
On Friday, 14 July 2017 at 16:43:42 UTC, Anton Fediushin wrote: On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance. import std.algorithm : sort; import

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
On Friday, 14 July 2017 at 15:15:42 UTC, Steven Schveighoffer wrote: import std.algorithm: filter; import std.uni: isWhite; line.filter!(c => !c.isWhite).to!string; be warned, this is going to be a bit slow, but that's the cost of autodecoding. If you are looking for just removing ascii

sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
Is there a 'easy' way to sort a string in D like it is possible in Python? Also how can I remove whitespace between characters if I am reading a line from a file and safe it as a string? string[] buffer; foreach (line ; File("test.txt").byLine) buffer ~= line.to!string;

Help me fix my compiler

2017-07-12 Thread Namal via Digitalmars-d-learn
Hello, I used the Install Script command line to install the newest dmd compiler (Ubuntu 16.04.2 LTS). Now I have to type 'source ~/dlang/dmd-2.074.1/activate' before I can use it and it is also not show in the software center like it used to be. How can I fix it or how can I remove it?

Re: reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array.

Re: reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote: Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array. Also, it should be saved as an integer.

reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
Hello, comming from C++, I find it hard to remember and understand how reading from file should be done in D. Especially since I am not very good in functional programming. So I have a file which looks like this: 1,2,3,4 5,6,7,8 9,11,11,12 and so on How could I read it row by row and create

Re: How to set array length for multidimensional static arrays

2016-02-01 Thread Namal via Digitalmars-d-learn
Sorry guys that I didn't express myself well. I also mixed some stuff up. What I wanted to ask is this, in c++ this is valid int x = 3; int y = 10; int arr [x][y]; x,y are known at the compile time and arr is a static array. I can't do that in D so what is the best way

Re: How to set array length for multidimensional static arrays

2016-02-01 Thread Namal via Digitalmars-d-learn
On Monday, 1 February 2016 at 12:12:00 UTC, Jonathan M Davis wrote: On Monday, February 01, 2016 11:15:40 Namal via Digitalmars-d-learn wrote: Sorry guys that I didn't express myself well. I also mixed some stuff up. What I wanted to ask is this, in c++ this is valid int x = 3; int y

Re: How to set array length for multidimensional static arrays

2016-01-31 Thread Namal via Digitalmars-d-learn
On Monday, 1 February 2016 at 07:41:33 UTC, Namal wrote: I understand that I cannot pass a variable to the static array like in C++, and have to use dynamic arrays. But how can I set the length for them without using a loop? I mean std::vector in C++, not array.

is there a set container?

2016-01-25 Thread Namal via Digitalmars-d-learn
Hello, I am looking for data structure equivalent to std::set from C++. Couldn't find it in the documentation.

Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
Hello, finally I want to learn how to do it right and I tried to understand it from here https://en.wikibooks.org/wiki/D_(The_Programming_Language)/d2/Modules But I have a few questions. Do I have always to include std.stdio in every file like in the example or is it enough just to import

Re: Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 22:15:43 UTC, Adam D. Ruppe wrote: You can import it as long as you define it! I just tried to import one module with a main into another, but I get this: Error: only one main allowed

Re: Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 23:06:38 UTC, Adam D. Ruppe wrote: On Wednesday, 6 January 2016 at 23:00:43 UTC, Namal wrote: I just tried to import one module with a main into another, but I get this: You can't have two mains, but you can import a module with main from another module

Re: functional way doing array stuff/ lambda functions

2015-12-14 Thread Namal via Digitalmars-d-learn
On Sunday, 13 December 2015 at 01:01:07 UTC, cym13 wrote: That's because you want to modify it in product passing it by ref. Hmm, that seems different to c++. On Sunday, 13 December 2015 at 11:37:50 UTC, cym13 wrote: As cryptic as it is this means that the range you passed to reduce is

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread Namal via Digitalmars-d-learn
On Saturday, 12 December 2015 at 23:50:55 UTC, Xinok wrote: On Saturday, 12 December 2015 at 23:36:43 UTC, cym13 wrote: ... So, in your example: int product(const ref int[] arr) { import std.array: array; import std.algorithm: reduce; arr = arr.reduce!((p, i) => p*i).array; }

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread Namal via Digitalmars-d-learn
On Sunday, 13 December 2015 at 00:02:11 UTC, cym13 wrote: Now that I think about it, it's true that it would make no sense whatsoever to return a range as reduce is typically used to return a single value... At least it makes perfect sense. Thanks alot, this helped alot. But I have another

functional way doing array stuff/ lambda functions

2015-12-12 Thread Namal via Digitalmars-d-learn
Hello guys, I am still uncertain how to do it right when it comes to lambda functions. For instance: how do I multiply all the elements in an array ? int product(const ref int[] arr){ int p = 1; foreach(i;arr) p*=i; return p; }

Re: reading file byLine

2015-11-07 Thread Namal via Digitalmars-d-learn
On Saturday, 7 November 2015 at 17:13:33 UTC, Namal wrote: On Saturday, 5 September 2015 at 14:49:13 UTC, deed wrote: On Saturday, 5 September 2015 at 14:44:19 UTC, deed wrote: .map!(s => chomp(s, "\"") .map!(s => chompPrefix(s, "\"") should be .map!(s => chomp(s, "\"")) .map!(s =>

Re: reading file byLine

2015-11-07 Thread Namal via Digitalmars-d-learn
On Saturday, 5 September 2015 at 14:49:13 UTC, deed wrote: On Saturday, 5 September 2015 at 14:44:19 UTC, deed wrote: .map!(s => chomp(s, "\"") .map!(s => chompPrefix(s, "\"") should be .map!(s => chomp(s, "\"")) .map!(s => chompPrefix(s, "\"")) Hello again, Now I have a file that

Re: conver BigInt to string

2015-11-06 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179;

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 17:13:07 UTC, Ilya Yaroshenko wrote: string s1 = to!string(a).dup.sort.idup; well, but I was just told not to use sort ??

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I do wrong?

Re: How to detect overflow

2015-11-04 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 07:59:44 UTC, Ali Çehreli wrote: On 11/03/2015 11:52 PM, Namal wrote: http://dlang.org/phobos/core_checkedint.html It says: "The overflow is sticky, meaning a sequence of operations can be done and overflow need only be checked at the end." But how can I

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx. for many of them it is as

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:10:43 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:10:43 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each

How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 04:22:03 UTC, BBasile wrote: On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote: Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824 You can use

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 04:22:03 UTC, BBasile wrote: On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote: Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824 You can use

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
Hello guys, I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx.

foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn
Is it possible to create a foreach loop with a breakstetemen? I mean something like that for the second loop where i want to break if element from: int [] g = [9,15,21]; int [] v = [2,3,5,7,8,9,11,13,17,19]; foreach(j;1..10) for(int i = 0; v[i]

Re: foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn
On Monday, 19 October 2015 at 14:43:04 UTC, Rikki Cattermole wrote: On 20/10/15 3:28 AM, Namal wrote: Is it possible to create a foreach loop with a breakstetemen? I mean something like that for the second loop where i want to break if element from: int [] g = [9,15,21]; int [] v =

Re: foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn
Is it possible to use foreach backwards? foreach(int i;20..1) writeln(i); compiles but I get nothing.

Tree datatype

2015-10-14 Thread Namal via Digitalmars-d-learn
Hello, I don't remember exactly but I think when I first saw D code there was tree datatype implemented without pointers. Is it possible to make a tree struct without pointers?

Re: How to do unittests

2015-10-02 Thread Namal via Digitalmars-d-learn
On Wednesday, 30 September 2015 at 14:44:20 UTC, qsdf wrote: On Wednesday, 30 September 2015 at 14:20:28 UTC, Namal wrote: On Wednesday, 30 September 2015 at 13:03:52 UTC, Rikki Cattermole wrote: On 01/10/15 1:59 AM, Namal wrote: Hello, can someone give me a complete example please how to do

How to do unittests

2015-09-30 Thread Namal via Digitalmars-d-learn
Hello, can someone give me a complete example please how to do unittests? I tried this with the example from german wikipedia, but the flag -unittest didn't make any difference.

Re: How to do unittests

2015-09-30 Thread Namal via Digitalmars-d-learn
On Wednesday, 30 September 2015 at 13:03:52 UTC, Rikki Cattermole wrote: On 01/10/15 1:59 AM, Namal wrote: Hello, can someone give me a complete example please how to do unittests? I tried this with the example from german wikipedia, but the flag -unittest didn't make any difference.

Re: reading file byLine

2015-09-18 Thread Namal via Digitalmars-d-learn
Hello guys, is there a nice functional way to read the file which is like 1,2,3,4,5,6 2,3,4,5,6,7 8,9,0,9,2,3 line by line, split numbers and remove each ',' convert it to int and save in a matrix int[][] arr?

Re: reading file byLine

2015-09-18 Thread Namal via Digitalmars-d-learn
On Friday, 18 September 2015 at 10:34:41 UTC, Edwin van Leeuwen wrote: On Friday, 18 September 2015 at 10:26:46 UTC, Namal wrote: Hello guys, is there a nice functional way to read the file which is like 1,2,3,4,5,6 2,3,4,5,6,7 8,9,0,9,2,3 line by line, split numbers and remove each ','

Re: reading file byLine

2015-09-18 Thread Namal via Digitalmars-d-learn
On Friday, 18 September 2015 at 11:37:15 UTC, Edwin van Leeuwen wrote: On Friday, 18 September 2015 at 11:11:51 UTC, Namal wrote: compiles but crashes For me it works fine. You probably have extra spaces or something in your file. It would help if you posted the error message you get when

Re: reading file byLine

2015-09-18 Thread Namal via Digitalmars-d-learn
On Friday, 18 September 2015 at 11:06:46 UTC, Edwin van Leeuwen wrote: On Friday, 18 September 2015 at 10:48:25 UTC, Namal wrote: On Friday, 18 September 2015 at 10:34:41 UTC, Edwin van Leeuwen wrote: On Friday, 18 September 2015 at 10:26:46 UTC, Namal wrote: Hello guys, is there a nice

Re: reading file byLine

2015-09-18 Thread Namal via Digitalmars-d-learn
So do I understand it right: does => in map! indicates a lambda function?

Re: Why does reverse also flips my other dynamic array?

2015-09-12 Thread Namal via Digitalmars-d-learn
Why is also b flipped here? This doesn't happen if I use static arrays. nvm. I need to .dup that.

Re: reading file byLine

2015-09-12 Thread Namal via Digitalmars-d-learn
On Monday, 7 September 2015 at 10:28:20 UTC, deed wrote: On Monday, 7 September 2015 at 10:25:09 UTC, deed wrote: writeln(x);// or you can pass it to a function. I meant `writeln(x + 5)` If I have just red your post before I started using reverse on dynamic arrays... Anyway, there is

Sum and other algorithm functions

2015-09-10 Thread Namal via Digitalmars-d-learn
Hello, how can I define the range for the sum function which I want to sum up? For instance how do I sum up the first 3 elements of an array int[] a = [1,2,3,4,5,6,7,8,9]; or the last 3?

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
On Sunday, 6 September 2015 at 20:39:27 UTC, deed wrote: On Sunday, 6 September 2015 at 17:57:49 UTC, Namal wrote: Yeah, I just checked, it is 2.066, how can I install the new version on ubuntu with sudo apt-get? sudo apt-get install dmd will give you dmd v2.067.1. Don't know when it will

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
That should be it though... Could you try this minimal complete test? import std.stdio; import std.algorithm; void main(string[] args) { int[] arr = [1, 2, 4, 2, 3, 4, 1]; arr.sort.uniq.writeln; } // [1, 2, 3, 4] yes, it works likte that. unique(arr) I get Error: undefined

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
Well, if you don't type function names right, it will be hard to help you. oh, sorry. But I found out what I have been doing wrong besides that. arr.sort.uniq; uniq(arr) or arr.sort.uniq; compiles but doesn't store it in the arr array, I need to store it in a new one.

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
Are you on 2.066 or older? Back then std.algorithm hasn't been split into submodules yet. Just import std.algorithm then instead of std.algorithm.comparison, std.algorithm.iteration, etc. Yeah, I just checked, it is 2.066, how can I install the new version on ubuntu with sudo apt-get? I

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
Note that there's a specialized `std.algorithm.iteration.sum`. is there any function that removes double elements in a sorted array?

Re: reading file byLine

2015-09-06 Thread Namal via Digitalmars-d-learn
On Sunday, 6 September 2015 at 15:52:38 UTC, anonymous wrote: On Sunday, 6 September 2015 at 15:41:34 UTC, Namal wrote: is there any function that removes double elements in a sorted array? std.algorithm.iteration.uniq http://dlang.org/phobos/std_algorithm_iteration.html#uniq Hmm, I get

Re: reading file byLine

2015-09-05 Thread Namal via Digitalmars-d-learn
On Saturday, 5 September 2015 at 18:57:52 UTC, deed wrote: On Saturday, 5 September 2015 at 17:31:39 UTC, Namal wrote: Yeah, I have have been trying this example from wiki books https://en.wikibooks.org/wiki/Learning_D_With_Project_Euler It is not even compiling. What exactly is not

Re: reading file byLine

2015-09-05 Thread Namal via Digitalmars-d-learn
On Saturday, 5 September 2015 at 14:49:13 UTC, deed wrote: On Saturday, 5 September 2015 at 14:44:19 UTC, deed wrote: .map!(s => chomp(s, "\"") .map!(s => chompPrefix(s, "\"") should be .map!(s => chomp(s, "\"")) .map!(s => chompPrefix(s, "\"")) Yeah, I have have been trying this

Re: reading file byLine

2015-09-05 Thread Namal via Digitalmars-d-learn
On Friday, 4 September 2015 at 12:09:19 UTC, Edwin van Leeuwen wrote: On Friday, 4 September 2015 at 12:06:08 UTC, Edwin van Leeuwen wrote: On Friday, 4 September 2015 at 11:50:23 UTC, deed wrote: import std.algorithm, std.range, std.array, std.string, std.stdio, std.conv; int[] arr1 = [1,

Re: reading file byLine

2015-09-04 Thread Namal via Digitalmars-d-learn
On Friday, 4 September 2015 at 01:55:13 UTC, deed wrote: On Friday, 4 September 2015 at 01:31:28 UTC, Namal wrote: How can I get just the maximum element? Do I need to give a range for it? Use max? http://dlang.org/phobos/std_algorithm_comparison.html#max Sorry, I don't understand the

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 22:19:11 UTC, wobbles wrote: On Wednesday, 2 September 2015 at 21:53:20 UTC, Namal wrote: Thx guys, this helped alot. The next thing I want to do is read the file line by line and split the stream into words. I found this example of code that seems to do sort

How to test if a double has no fraction part

2015-09-03 Thread Namal via Digitalmars-d-learn
Hello, is there a modf function like in C++ or something similar which could help me find out if a double has a fractional part or not. Thx

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
Sorry, I didn't notice the "convert all the elements in it to integer" part. I think I saw reference to the to! before...that is one way to convert. auto words = file.byLine() // you've all lines in range .map!(a => a.split) .map!(a =>

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
On Thursday, 3 September 2015 at 23:54:44 UTC, H. S. Teoh wrote: On Thu, Sep 03, 2015 at 11:38:54PM +, Namal via Digitalmars-d-learn wrote: On Thursday, 3 September 2015 at 23:31:27 UTC, Jordan Wilson wrote: >On Thursday, 3 September 2015 at 23:28:37 UTC, Namal wrote: >>On Th

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
On Thursday, 3 September 2015 at 23:31:27 UTC, Jordan Wilson wrote: On Thursday, 3 September 2015 at 23:28:37 UTC, Namal wrote: On Thursday, 3 September 2015 at 23:25:52 UTC, Jordan Wilson wrote: And also: import std.algorithm Sorry, I should have taken the time to answer properly and fully.

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
ep18.d(10): Error: no property 'split' for type 'char[]' /usr/include/dmd/phobos/std/algorithm.d(427): instantiated from here: MapResult!(__lambda1, ByLine!(char, char)) ep18.d(10):instantiated from here: map!(ByLine!(char, char)) and then a long list to the end of my code

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
On Thursday, 3 September 2015 at 23:25:52 UTC, Jordan Wilson wrote: And also: import std.algorithm Sorry, I should have taken the time to answer properly and fully. import std.file, std.stdio, std.string, std.conv, std.algorithm; void main(){ auto file = File("text.txt");

Re: How to test if a double has no fraction part

2015-09-03 Thread Namal via Digitalmars-d-learn
Interesting, in contrary to C++ it saves the integral part in the dummy variable. Doing this I noticed if I try to write a double variable in the console it gives me only the integral part. I only did it with writeln so far. How can I print out a double variable with a precision of 2 for

Re: reading file byLine

2015-09-03 Thread Namal via Digitalmars-d-learn
Hope this helps. Yes, it does. I have a question about arrays. I can sort an array A by sort(A); How can I get just the maximum element? Do I need to give a range for it?

Re: reading file byLine

2015-09-02 Thread Namal via Digitalmars-d-learn
Thx guys, this helped alot. The next thing I want to do is read the file line by line and split the stream into words. I found this example of code that seems to do sort of something like it. How can I modyfy it so I can store the words in an array of strings? Is a => a.length the iterator

Re: reading file byLine

2015-09-02 Thread Namal via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 13:12:39 UTC, cym13 wrote: On Wednesday, 2 September 2015 at 13:01:31 UTC, Namal wrote: Hello, I want to read a file line by line and store each line in a string. I found this example with byLine and ranges. First of all, do I need the range lib at all to do

reading file byLine

2015-09-02 Thread Namal via Digitalmars-d-learn
Hello, I want to read a file line by line and store each line in a string. I found this example with byLine and ranges. First of all, do I need the range lib at all to do this and if so what is the range of the end of the file?

Re: array function

2015-08-31 Thread Namal via Digitalmars-d-learn
On Monday, 31 August 2015 at 11:27:20 UTC, Rikki Cattermole wrote: You cannot define static arrays using runtime information. You must use dynamic arrays. int[] foo(int N) { int[] v; v.length = N; // do something with it int[] 2; return s; } Of course

array function

2015-08-31 Thread Namal via Digitalmars-d-learn
Hello, can someone explain to me please what I am doing wrong by passing an integer to this function and then just creating a static array? The error I get is: Error: variable N cannot be read at compile time int[] foo(int N){ int[N] v; //do something with it int[]

Re: array function

2015-08-31 Thread Namal via Digitalmars-d-learn
Hey guys, since I am learning D arrays here, can you tell me the best way to remove an element at the end of an array or at some index i?

Re: array function

2015-08-31 Thread Namal via Digitalmars-d-learn
On Monday, 31 August 2015 at 12:00:26 UTC, bearophile wrote: Namal: std::vector foo(int N){ std::vector V(N); int some_array[N]; VLAs are not present in D. Bye, bearophile Yah, I guess I have been damaged with them when I started to learn programming in C++ >(

Setting um makefile for dmd

2015-06-30 Thread Namal via Digitalmars-d-learn
Hello, i get myself a nice makefile from here: https://gist.github.com/darkstalker/2221824 How can I modify it so that I can use the run option of dmd? I tried to add another compiler flag variable which would be only used with run but then it messed with -of$@ option and said it couldn't