-1

my problem is that if i use the String hardcode the answer is correct but if i use the inputed String not working . for example :

 String variable = " \u0020\uFEB3\uFEE8\uFB93\u0020\uFEBB\uFE92\uFEEE\u0631\u0020";
 TextView show = (TextView) findViewById(R.id.preshow);
 show.settext(variable );

textview shows : صنگ صبور

but:

  File filematn = new File(Environment.getExternalStorageDirectory()+File.separator+"SingingStudio/"+songname+"/"+songname+"file.txt");
    //Read text from file
    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(filematn));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        br.close();
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }
    String variable = text.toString();
    TextView show = (TextView) findViewById(R.id.preshow);
    show.settext(variable );

textview shows : \u0020\uFEB3\uFEE8\uFB93\u0020\uFEBB\uFE92\uFEEE\u0631\u0020

how can i fix it . thank you

1 Answers1

0

When you're reading in the file, the backslashes are being escaped with a preceding backslash. Getting around this is not as simple as it appears but is covered in this SO question: How to replace \\u by \u in Java String

Community
  • 1
  • 1
Robert Bain
  • 9,113
  • 8
  • 44
  • 63
  • What method did you use to remove the backslashes out of curiosity? – Robert Bain Nov 15 '14 at 20:33
  • Pattern unicode = Pattern.compile("\\\\u(.{4})"); Matcher matcher = unicode.matcher("aaa\\u2022bbb\\u2014ccc"); StringBuffer sb = new StringBuffer(); while (matcher.find()) { int code = Integer.parseInt(matcher.group(1), 16); matcher.appendReplacement(sb, new String(Character.toChars(code))); } matcher.appendTail(sb); – user2962004 Nov 16 '14 at 12:57