简体   繁体   中英

How to display tabs(whitespace) coming from MySQL database correctly on both in Android and IOS app?

I have following data in my db row:

Espresso:                           7,00

Double Espresso:                    8,00

Ristretto:                          7,00

Espresso Machiato:                  8,00

Espresso Con Panna:                 8,00

I write it on Word, then copy & paste to MySQL editor. When I save it, my IOS and Android apps cannot show the prices aligned because of the tab characters.

在此输入图像描述

What is the best way to do that?

The best way- those 2 things are different data and are in different columns in your database, I would expect (if not, you need to fix your schema). So put the 2 strings in separate TextViews, and align the text view in xml.

First you can split the data from tab character and use formatting like below in java. I believe in objective-c it should be similar.

    String ehe = String.format("%-20s : \t %4dTL \n","ehemehe",23);
    String ehe2 = String.format("%-20s : \t %4dTL \n","ehemeheadawd",44);
    System.out.println(ehe);
    System.out.println(ehe2);

Output it produces is

ehemehe              :     23TL 

ehemeheadawd         :     44TL

replace the "/t" chars with "" before you display the text. by using

String.replace("/t","");

如果您预先计算了空格数,请使用固定宽度的字体。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM