how to find \n in string in dart

Viewed 1393

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?

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.

Related