6

I have a string in my maven project and when I run it on my local machine, I have

String name = title.get(i).text().replace("é", "e");

Later I save the variable name to a file

But then when I export to .jar and run the it on my server I see é not e, but when I run on my local machine I see "e" which is what I want.

What is happening?

Srijani Ghosh
  • 3,935
  • 7
  • 37
  • 68
spen123
  • 3,464
  • 11
  • 39
  • 52
  • What is the type of `title`? – Enamul Hassan Aug 23 '15 at 23:27
  • 8
    I don't think you've given enough information to answer this question. It probably has something to do with the platform's default charset or file encoding, and nothing to do with `String.replace`. – Chris Martin Aug 23 '15 at 23:29
  • @ChrisMartin when you say platform you mean the server I am trying to run it on?, but it runs normal java how would it not do replace? – spen123 Aug 23 '15 at 23:32
  • 1
    @spenf10 try [this](http://stackoverflow.com/questions/1001540/how-to-write-a-utf-8-file-with-java/1001568#1001568) or [this](http://stackoverflow.com/questions/1001540/how-to-write-a-utf-8-file-with-java/1001982#1001982) – Enamul Hassan Aug 23 '15 at 23:36
  • Where are the text values coming from? I wonder if perhaps your strings contain the single character `'\u00e9'` when you run the program locally, whereas the strings on your server contain the sequence `'\u0065\u0301'`. If that's the case, you can create a [Matcher](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html) outside your loop using `Matcher matcher = Pattern.compile("e", Pattern.CANON_EQ).matcher("");`, and inside your loop, you can do `String name = matcher.reset(title.get(i).text()).replaceAll("e");`. – VGR Aug 25 '15 at 00:32
  • Please provide a [mcve] – CosmicGiant Nov 06 '15 at 21:06

1 Answers1

1

If you are trying to change that from a web page you may want to try:

String name = title.get(i).text().replace("%C3%A9", "e");