SparkFun Forums 

Where electronics enthusiasts find answers.

General MicroView Support area - You have questions, find your answers here.

Moderators: marcus@geekammo, Help@GeekAmmo

By AUArduino
Is there a command to concatenate a string. If not, is there some way to find the length of a string or where it'll end. Hoping there is a way to do it so I don't have to hard code the set cursor command after every word or variable. Thanks.
By Help@GeekAmmo
Hi @AuArduino,

You can use the command getFontWidth() to return the current font width, then calculate the length of your string, and multiply them to get the total width. Then compare with getLCDWidth() to check if the string fit on the LCD width. Below is the example. Hope this helps.

Code: Select all
#include <MicroView.h>

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly: 
  int fontWidth = uView.getFontWidth();
  char strTest[]="Hello";
  char strTest2[]="Hello World Test" ;
  int strTestLen=strlen(strTest);
  int strTest2Len=strlen(strTest2);
  if ((strTestLen*fontWidth)<uView.getLCDWidth()) 
    uView.print("Not Fit");
  if ((strTest2Len*fontWidth)<uView.getLCDWidth()) 

By scotta
Is your code example correct? I did a test with the 5 x 7 font and found that getFontWidth() returns 5, which doesn't account for the extra pixel space between characters. At least for the 5 x 7 font, I think you have to multiply the string length by (uView.getFontWidth() + 1).
By Help@GeekAmmo
Hi Scott,

In the actual font file, there is no extra pixel space, so getFontWidth() returning 5 is technically correct.

Depending on how a user wish to display the text, if user is using print() then adding 1 to the getFontWidth() will get the desired result, if the user wish to drawChar() manually without extra pixel space, then getFontWidth() without adding 1 will be correct.

So it all depends on the situation. My example only serves as a basis for the explanation.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]