Extract sub string from a string

Виталий Фадеев vital.fadeev at gmail.com
Mon Nov 9 17:54:40 UTC 2020


On Monday, 9 November 2020 at 16:00:28 UTC, Vino wrote:
> Hi All,
>
>    Request your help on how to extract sub string from a 
> string, below is an example in PHP, need your help on how to do 
> the same in D.
>
> $text = "welcome2worldinfo";
> $hg = strtoupper(substr($text , 0, 7).'-'.substr($text, 7, 
> 1).'-'.substr($text, 8, 5));
> print_r($hg) \\ Output : WELCOME-2-WORLD
>
> From,
> Vino.B

Some like this:

substr($text , 0, 7) // --> text[ 0 .. 7 ]
substr($text, 7, 1)  // --> text[ 7 .. 7+1 ]
substr($text, 8, 5)  // --> text[ 8 .. 8+5 ]

$hg = a . b . c      // --> string hg = a ~ b ~ c;

strtoupper( s )      // --> s.toUpper

print_r($hg)         // --> writeln( hg )

And import names:
import std.uni : toUpper;
import std.stdio : writeln;

Help:
https://dlang.org/phobos/std_uni.html
https://dlang.org/phobos/std_stdio.html
https://dlang.org/spec/arrays.html#strings



More information about the Digitalmars-d-learn mailing list