Android - concatenate two strings of different languages

I cannot find a solution to this "simple" action:

I am trying to add 2 lines to get the full file path (folders and filename):

String a = /storage/emulated/0/abc/לכ

 this has non-english letters and

String b = 20141231_042822.jpg

String c = a + b





(Tried also with StringBuilder)


source to share

2 answers

Use char[]

instead and add them one by one using this method:

public char[] generatePath(String a, String b){
    if(a==null || b==null)
        return null;

    char[] result = new char[a.length() +b.length()];

    for(int i=0;i<a.length();i++)

    for(int i=a.length();i<a.length()+b.length();i++)

    return result;


This ensures that each character is in the right place.


objects in Java are not encoded (*).

The only one that has an encoding is byte[]

. So if you need UTF-8 then you will need byte[]

. If you have String

contains unexpected data, then the problem is at some earlier location that incorrectly converted some binary data to String

(i.e. using incorrect encoding).

(*), which is not entirely accurate. In fact, they are encoded, but that is UTF-16 and cannot be changed. source: answer

What you need to do is use byte[]

String instead

Try this



or this

byte[] ptext = String.getBytes("UTF-8");




Try using BidiFormatter

For example :

private static String text = "%s הוא עסוק";
private static String phone = "+1 650 253 0000";

String wrappedPhone = BidiFormatter.getInstance(true /* rtlContext */).unicodeWrap(phone);
String formattedText = String.format(text, wrappedPhone);




All Articles