Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count Carriage Returns or Line Feeds in a String in Dart

Tags:

dart

I need to count the number of CR or LF or LF + CR in a String. I'm doing this:

String content = "\r dasdsad \r asdasdasd \r";
int count = content.allMatches('\r').length;
print('count: $count');

But I get always zero as count value.

like image 474
Fedy2 Avatar asked Feb 10 '23 19:02

Fedy2


1 Answers

You have to inverse '\r' and content :

String content = "\r dasdsad \r asdasdasd \r";
int count = '\r'.allMatches(content).length;
print('count: $count');
like image 142
Alexandre Ardhuin Avatar answered Feb 16 '23 01:02

Alexandre Ardhuin