Note that there are some explanatory texts on larger screens.

plurals
  1. PO"En dash" being garbled during http response handling or text manipulation
    primarykey
    data
    text
    <p>I'm writing code to work with text from Wikipedia and am having issues with en dashes being garbled. I haven't worked with en dashes or other non-standard characters before (non-standard to me being character that don't appear on my keyboard ;), so I'm not sure where to point the finger at what I'm doing wrong. Here's what is happening, along with code snippets.....</p> <p>I send a request to Wikipedia (I'm using the Apache HttpComponents client API for communicating with Wikipedia) for the contents of an article and save it in a String:</p> <pre><code>DefaultHttpClient client = new DefaultHttpClient(); HttpGet queryRequest = new HttpGet(query); // query is the URL for retrieving the article contents. ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = client.execute(queryRequest, responseHandler); </code></pre> <p>At this point if I were to send "responseBody" to System.out, en dashes are displayed in my Eclipse console as '?'. This might just be an Eclipse console display issue so I'll move on.</p> <p>I manipulate the text, ignoring the en dashes, and then send the text back to Wikipedia. </p> <pre><code>List&lt;NameValuePair&gt; postParams = new ArrayList&lt;NameValuePair&gt;(); postParams.add(new BasicNameValuePair("text", content); // content is a String with the article text UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams, "UTF-8"); HttpPost queryRequest = new HttpPost(url); // url is the basic URL for the Wikipedia api queryRequest.setEntity(entity); queryRequest.addHeader("Content-Type", "application/x-www-form-urlencoded"); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = client.execute(queryRequest, responseHandler); </code></pre> <p>When the text, now uploaded to Wikipedia, is displayed in a web browser what was en dashes before are now displayed as '?' in a box (unknown character?). Therefore, somewhere I am inadvertently changing or miscoding the en dashes, but I'm not sure exactly where. </p> <p>Can someone point me in the right direction?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload