Obsecure problem 1

pascal111 judas.the.messiah.111 at gmail.com
Sat Jul 30 21:24:50 UTC 2022


I've typed a code to enjoy with my library "dcollect", and found 
non-understandable error:

module main;

import std.stdio;
import dcollect;
import std.string;
import std.conv;


int main(string[] args)
{

         string sentence_x,
         sent_result, token2;
         string[] sentence_tokens;

         writeln(strstring(5,"*")," No tail \"s\" 
",strstring(5,"*"));
         writeln;

         write("Compose a line: ");
         sentence_x=strip(readln());

         sentence_tokens=sentence_x.d_strtok(" ,;.:!?\"'");

         foreach(token; sentence_tokens){
             token2=token.strrtrim;
             if(token2[token2.length-1]=='s')
                 token2=strdel(token2, token2.length-1,1);
                 sent_result~=token2~" ";}

         sent_result.writeln;

     	return 0;
     }


dcollect library:
https://github.com/pascal111-fra/D/blob/main/dcollect.d

I changed some data types of some functions parameters to "ulong":

string strdel(const string ch, ulong x, ulong l )
{

         string l_ch=ch.strleft(x);
         string r_ch=ch.strright(ch.length-(x+l));

         return (l_ch~=r_ch);

}

string strleft(const string ch, ulong n)
{

         string ch_sub;

         ch_sub=ch[0..n];

         return ch_sub;

}

/************************************/

string strreverse(const string ch)
{

         string ch_rev;

         for(ulong i=ch.length-1; i>=0; i--)
             ch_rev~=ch[i];


         return ch_rev;


}

/*********************************************/

string strright(const string ch, ulong n)
{

         string ch_sub1,
         ch_sub2;

         ch_sub1=strreverse(ch);

         ch_sub2=strleft(ch_sub1, n);

         ch_sub1=strreverse(ch_sub2);

         return ch_sub1;

}

====================

Running screen says:

https://i.postimg.cc/G3YyCmbF/Screenshot-from-2022-07-30-23-23-59.png


More information about the Digitalmars-d-learn mailing list