hitch45
hitch45

Reputation: 492

Android multi-line textview - character count of a particular line?

I'm trying to get the character count of a particular line of a multi-line textview. Based on other posts, I've gotten the Layout of the textview in question. I see several methods that pass in an (int line), but none that return a character count of a particular line? Am I just missing it? Any help would be appreciated.

Upvotes: 0

Views: 1408

Answers (2)

A. Abiri
A. Abiri

Reputation: 10810

This will split the text in the textview by lines.

String text;
String[] lines = text.split("\\r?\\n");
int characterCount = lines[0].length();

Upvotes: 2

Pengume
Pengume

Reputation: 570

if your just trying to get the count of a string, have you tried String.length(myString) to return a count of how many characters are in the string?

Upvotes: 0

Related Questions