I have a TextView and I would like to get the last line of the buffer to a variable.Currently what I can do is ;
but I am trying to get the only last line of input. What are your suggestions ?
Thanks in advance,
I imagine you simply want
auto const buffer = m_TextView.get_buffer();
auto const lines = buffer->get_line_count();
auto const iter = buffer->get_iter_at_line(lines - 1); // N.B.
auto const ustring = buffer->get_text( iter, buffer->end() );
The documentation shows various ways like this of getting iterators to points within the buffer, and then
get_text() lets you cut out just the parts between two iterators (or
get_slice() is similar with some documented differences).
get_iter_at_line() expects an index starting from 0, not 1, so we must adjust the count minus 1 for that, but that’s usual for C++ sizes vs indexes
Thank you for the reply, it really helped me a lot!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.