Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find \n in string in dart

Tags:

flutter

dart

I have a json file from which I read an array of objects.

Now I have situation where, if some object contains \n, then I have to do some extra operations. To check whether the objects contain \n, or not, I do the following...

String normalString = 'somethin \n and something';    
String jsonString = jsonFileData['some_field'];    
print(normalString.contains('\n')); //true 
print(jsonString.contains('\n')); // false

If I do string.contains() with simple string it returns true, but if I check check the json file as a string false is returned.

Why is this so?

like image 223
ketiwu Avatar asked Dec 10 '25 15:12

ketiwu


1 Answers

The most probable answer to your question is that jsonFileData['some_field'] is not a string. As you are putting it in a string, the toString method is called on that object and returns something that is not what you intend. Thus, when you search for '\n', it is not found.

like image 187
Muldec Avatar answered Dec 13 '25 09:12

Muldec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!