Home > Blockchain >  How to print Specific Part of String in Dart?
How to print Specific Part of String in Dart?

Time:10-06

I want to print specific part of String in dart Example:

String sample = "Hello World";

Output:

llo Wor

Like In Python We do this simply By:

print(sample[2:-2])

But How to achieve this in Dart Language

If you know the Solution then answer this question.

CodePudding user response:

use substring

String sample = "Hello World";

Output:

llo Wor

code in dart

print(sample.substring(2, 9));

CodePudding user response:

You Can Do this With subString Method In Dart Like This:

String sample = "hello world";
print(sample.subString(2,7);

if You want to Specify Number of Letters From End Then Do This.

print(sample.subString(2,sample.length-2);

CodePudding user response:

You can simply use the substring method.

like so:

print(helloWorldText.substring(2, helloWorldText.length -2));

Here is the example in Dartpad.
https://dartpad.dev/c15474ddb5402fef40e73332a41642cd?null_safety=true

  • Related