Zilaid
Zilaid

Reputation: 563

How to print Specific Part of String in Dart?

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.

Upvotes: 0

Views: 1134

Answers (3)

Zilaid
Zilaid

Reputation: 563

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);

Upvotes: 1

FadyFouad
FadyFouad

Reputation: 948

use substring

String sample = "Hello World";

Output:

llo Wor

code in dart

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

Upvotes: 1

BLKKKBVSIK
BLKKKBVSIK

Reputation: 3548

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

Upvotes: 0

Related Questions