How to split a string only on the first occurrence of a character in Dart

1 Answer

0 votes
void main() {
    String str = "date: 14:10:2022";
    
    int index = str.indexOf(":");
    
    List lst = [str.substring(0, index).trim(), str.substring(index + 1).trim()];
     
    print(lst[0]);
    print(lst[1]);
}
 
 
 
 
/*
run:
 
date
14:10:2022
 
*/

 



answered Oct 14, 2022 by avibootz

Related questions

1 answer 173 views
2 answers 171 views
1 answer 130 views
1 answer 109 views
...