Blupixel IT Blog – Computer Science and Web Developing Articles

Offical Blog of Blupixel IT Srl

Convert text to table in Android SDK

In Android, the management of text can be really difficult.

To visualize a text in a tidy way, like in a table, for example, you have to create a special layout, add elements and fill each cell with one portion of the text.

But if you have a normal text and you want to align it as in a table, using a normal TextView, you can use the following trick, that calculate the width of the text and add as many white spaces as needed to reach the fixed width of the cell.

String lines[] = getItem(position).toString().split("\n");
String print = "";
String parts[] = null;
String tmp = "";
int weight = 0;
for (int i=0; i < lines.length; i++) {
   if (!lines[i].equalsIgnoreCase("")) {
	   parts = lines[i].split(":", 2);
	   tmp = "";
	   Paint textPaint = text.getPaint();
	   float width = textPaint.measureText(parts[0]);
	   float wslength = textPaint.measureText(" ");
	   for (int j = 0; j < (220 - Math.round(width))/Math.round(wslength); j++) {
		   tmp = tmp + " ";
	   if (print.equalsIgnoreCase("")) {
		   print = print + parts[0] + tmp + Html.fromHtml(""+parts[1]+"");
	   } else {
		   print = print + "\n" + parts[0] + tmp + parts[1];

In the first part I split the string into lines, using the newline as the separator, Then I loop for each line and if it is not void I proceed.

I split every line in “cells” using the “:” character as sperator (in this case I consider I will have only 2 cells), the I take the rendered width of the text and I add as many spaces as needed to reach a width of 220.

If you have more than 2 cells, you will need to perform the same operation on all the cells ecluded the last one.

If it is the first row, I will use the bold as it is an header.

Then you can insert the print variable into a TextView or AlertDialog having the “table effect”.

Happy coding

Launch a second instance of skype on Linux Ubuntu

Sometimes a second instance of skype is needed to work with two different accounts.

Here you can find steps to follow to launch a second instance on a generic Linux system and later to add the icon to the Launch Bar on the left side in Ubuntu.

First of all create a new folde rinto your home

mkdir ~/.personalSkype

Then “duplicate” the skype executable to make the new windows are correctly linked to the new instance:

sudo ln -s /usr/bin/skype /usr/bin/skype2nd

Now you can runa the second instance using the command:

skype2nd --dbpath=~/.personalSkype


If you have Ubuntu and want to create an icon in the Launch bar, follow these steps:

1. Create a new icon for skype (for example a green “S”), call it skype-personal.png (you can use another name but you will have to edit the next file) and save it into /usr/share/icons/hicolor/64×64/apps/ (root privileges are needed)

2. Create a new file call SkypePersonal.desktop into the folder /usr/share/applications (you should be root) with this content

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Skype 2nd
Exec=skype2nd --dbpath=~/.personalSkype
Name=Skype 2nd

3. Open the folder /usr/share/applications in the File Manager and drag the new created file into the launch bar (usually on the left side of the scree)

Now you can launch the second instance by clicking the added icon.

Find a string in an array using C/C++

Unfortunately C/C++ is not easy as PHP.
To find a value inside an array, especially if arrays are of type char** instead of vector, you haven’t standard libraries to use.

The first negative aspect of char** is that you cannot use iterator and you need to know the length of the array to avoid to fall in “Segmentation Fault” error.

For who doesn’t know this error, it happens, usually, when you try to read or write an element of the array that’s not set or is outside the instantiated one.
So, if you have the array

int* arr = new int[5];


You can access arr[0], arr[1], arr[2], arr[3], arr[4] but if you try to access arr[5] o arr[10] you’ll get “Segmentation fault”

To search a tring inside an array is then needed to know the length of the vector.

Let’s see the function


using namespace std;

int array_search(char** input, int input_length, char* search) {

    int result = -1;
    string tmp;

    for(int i = 0; i < input_length; i++) {
        if (strcmp(input[i], search) == 0) {
              result = i;

    return result;



In the function we take as input: the array char** to look into, its length and the word to search for.
The function iterate all the array and breaks if the result is found.
It return -1 if nothing is found or the word index if it’s found.

Note that the function is case sensitive, so “Mickey mouse” is different from “mickey mouse”. To make it insensitive a little more work is needed.

See you soon