0

How do I split a string into two based on it's length to display on a 2x16 LCD?

I have seen a function called length() to get the length of a string. But, any ideas how to split it in to 2x16 and trim the rest of the string?

Thanks

RS2322016
3841 gold badge3 silver badges12 bronze badges
asked Aug 28, 2015 at 7:34

2 Answers 2

3

String::Substring does take a start and an end value. So you can do something like this:

String s1 = longtext.substring(0,15);
String s2 = longtext.substring(16,31);
answered Aug 28, 2015 at 10:38
0
2

That's what String::substring() is for. Simply take the first 16 characters and the characters from 16 to 32, and output them.

answered Aug 28, 2015 at 7:44
2
  • But,what about the rest of the string? I need 2 x 16 of the 32. Substring only provides one part right? Commented Aug 28, 2015 at 9:54
  • 1
    Use it as many times as you need in order to get all desired substrings. Commented Aug 28, 2015 at 9:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.