How to remove � from a String?

MRefaat

What is that char ? and how to remove it from a String? I got it from a BufferedReader and i got it because i read the contents in a char array and this array has to be assigned to a particular size.So, i got the String like that "aaaaaaa����", and I tried trim and subString but didn't change anything:

 String a = "aaaaaaa����";
//subString
    int i = a.lastIndexOf("a");
    a = a.substring(0, i+1);
//trim
    a = a.trim();

And this is my way to read the input:

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
char[] a = new char[1000];
int line;
String responseLine, server_response = "";
while((line = in.read(a)) != -1) {
      responseLine = String.valueOf(a);
      server_response = server_response + responseLine;
     }
in.close();
return server_response;
MRefaat

finally i found a way to solve that, it's not a professional one but efficient enough. all i had to do is filling the char array with white spaces just before starting the while loop and then after receiving the whole response i have just to trim it before returning it :

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
char[] a = new char[1000];
int line;
String responseLine, server_response = "";
for(int i = 0; i < a.length; i++){ //
      a[i] = ' ';                  // this is the for loop i added
    }                              //
while((line = in.read(a)) != -1) {
      responseLine = String.valueOf(a);
      server_response = server_response + responseLine;
      for(int i = 0; i < a.length; i++){ //
          a[i] = ' ';                    // this is the for loop i added
        }                                //
     }
in.close();
return server_response.trim();     // this is where i return the response trimmed 

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to remove / dispose a broadcast variable from heap in Spark?

来自分类Dev

How do I remove the background from this kind of image?

来自分类Dev

Remove words from the string which are present in list

来自分类Dev

How to remove xmlns="" from xml request

来自分类Dev

How to remove script initialisation from javaScript file

来自分类Dev

How to remove carriage returns and line feeds from a column?

来自分类Dev

How to get type from String?

来自分类Dev

How to Remove JavaScript Remnants from String in PHP

来自分类Dev

How to remove NA's from a kableExtra kbl table?

来自分类Dev

How to remove unused images from an Xcode project

来自分类Dev

How to remove tweet photos from twitter widget?

来自分类Dev

Remove alphanumeric word from string

来自分类Dev

Remove string from QStringList if string value is part of other string

来自分类Dev

How to remove apostrophe from text?

来自分类Dev

T-SQL - remove chars from string beginning from specific character

来自分类Dev

How to remove ANSI control chars (VT100) from a Java String

来自分类Dev

How to execute a GDB command from a string variable?

来自分类Dev

How to remove Children from an AbsoluteLayout in Xamarin.Forms?

来自分类Dev

How to retrieve values from junction table as a String?

来自分类Dev

How to create a list of Tab from a list of String?

来自分类Dev

How to remove all characters from a string before a specific character

来自分类Dev

How to remove every text from a website with Javascript

来自分类Dev

How to make a Node from a String?

来自分类Dev

How to remove 2 or more duplicates from list and maintain their initial order?

来自分类Dev

Remove time zones from a string or format HTTP TIME STRING in coldfusion

来自分类Dev

PHP: Can I remove &#8234; #&lrm; from string

来自分类Dev

How to remove key from Array of Object

来自分类Dev

Python 3: How to move an item from list x to list y and remove it from list x?

来自分类Dev

How to remove junk characters from the file generated by script command in linux

Related 相关文章

  1. 1

    How to remove / dispose a broadcast variable from heap in Spark?

  2. 2

    How do I remove the background from this kind of image?

  3. 3

    Remove words from the string which are present in list

  4. 4

    How to remove xmlns="" from xml request

  5. 5

    How to remove script initialisation from javaScript file

  6. 6

    How to remove carriage returns and line feeds from a column?

  7. 7

    How to get type from String?

  8. 8

    How to Remove JavaScript Remnants from String in PHP

  9. 9

    How to remove NA's from a kableExtra kbl table?

  10. 10

    How to remove unused images from an Xcode project

  11. 11

    How to remove tweet photos from twitter widget?

  12. 12

    Remove alphanumeric word from string

  13. 13

    Remove string from QStringList if string value is part of other string

  14. 14

    How to remove apostrophe from text?

  15. 15

    T-SQL - remove chars from string beginning from specific character

  16. 16

    How to remove ANSI control chars (VT100) from a Java String

  17. 17

    How to execute a GDB command from a string variable?

  18. 18

    How to remove Children from an AbsoluteLayout in Xamarin.Forms?

  19. 19

    How to retrieve values from junction table as a String?

  20. 20

    How to create a list of Tab from a list of String?

  21. 21

    How to remove all characters from a string before a specific character

  22. 22

    How to remove every text from a website with Javascript

  23. 23

    How to make a Node from a String?

  24. 24

    How to remove 2 or more duplicates from list and maintain their initial order?

  25. 25

    Remove time zones from a string or format HTTP TIME STRING in coldfusion

  26. 26

    PHP: Can I remove &#8234; #&lrm; from string

  27. 27

    How to remove key from Array of Object

  28. 28

    Python 3: How to move an item from list x to list y and remove it from list x?

  29. 29

    How to remove junk characters from the file generated by script command in linux

热门标签

归档