Assumptions and what you want to achieve

Please describe your question in detail here. This is a basic Dart question. I'd like to use a while statement to split characters one by one and output them vertically, but they appear together with the previous output. I'm not sure how to do this, so I'd like to see the output result.)

Problems and error messages

There are no errors.

There are no error messages.

void main() {
  String test='This is a test';
  stringCut(test);
}

StringCut(String a){

  for ( int textlong =a.length;textlong>=0; textlong--) {

    print(a.substring(textlong));

  }

}

Output.

current.

is is The output is This is a test. It is > test.

Ideal

is In In S Te

Things I've tried

Re-examined the use of subString and the while function.


Solution 1: whygee

subtring can take 2 parameters, the beginning of the substring and the end so you can do this

for ( int textlong = a.length; textlong > 0; textlong--) {
   print(a.substring(textlong-1, textlong));
}

to individually print characters one after the other.