0
How can i encode french Character?

let's say i have String strMEssage='Pour se désinscrire du service ';
String utf8 = new String(strMessage.getBytes("ISO8859_15"),"ISO8859_15"); 

o/P is not proper for special char ? is coming

ruhungry
  • 4,116
  • 18
  • 51
  • 93
user2888996
  • 327
  • 7
  • 18
  • 1
    Why use that? A `String` is a sequence of characters; just use the `String` as it! Where do you get the data from? Where does the problem appear? – fge Mar 21 '14 at 09:59
  • `String strMessage = "Pour se désinscrire du service";` with double quote not simple quote. that's all you need ;) it will work. It works with japanese so french is not a problem ;) – Clad Clad Mar 21 '14 at 10:00
  • @fge i have to send this String as Message Over SMPP protocol, so as End user the Mesage is not proper – user2888996 Mar 21 '14 at 10:01
  • @CladClad problem here is as End user..End User is not recieving proper message..see above comment – user2888996 Mar 21 '14 at 10:02

1 Answers1

2

You seem to be mixing a lot of concepts here.

A String is a sequence of chars. The fact that internally Java uses UTF-16 is irrelevant.

You never send Java Strings as is, nor receive a Java String, nor write Strings directly in a file, not read Strings directly from a file. You send/receive bytes. And turning bytes into characters and the reverse is made by a Charset{Decoder,Encoder}.

In Java source files, just write the string as you want it. When you send/write/receive/read it, use the correct encoding. That is all there is to it.

See Charset for generic information.

And if you use a Reader or Writer, always specify the encoding.

fge
  • 110,072
  • 26
  • 223
  • 312
  • what kind of Encoding i should use? – user2888996 Mar 21 '14 at 10:04
  • UTF-8, very probably. Use `StandardCharsets.UTF_8` in code where a `Charset` is asked for. – fge Mar 21 '14 at 10:05
  • i think i am unable to explain you my problem, i will try to make you understand: I have a message(French Message) which i am taking from DataBase and Sending to Customer on Phone.| Now the Communications Protocol is SMPP, so i am Using UCS-2 Encode Formatting. – user2888996 Mar 21 '14 at 10:11
  • Then use UTF-16. It is the same as UCS-2, except that UTF-16 supports Unicode code points above 0xFFFF (which UCS-2 doesn't) – fge Mar 21 '14 at 10:22
  • i used , still issue is same..:( – user2888996 Mar 21 '14 at 10:38
  • (sorry for the language) Bon, on va faire autrement: pose une autre question, mets-y le code que tu utilises actuellement et explique le problème que tu rencontres. – fge Mar 21 '14 at 10:40
  • 'public class Encoding { public static void main(String[] args) throws SocketTimeoutException, AlreadyBoundException, VersionException, SMPPProtocolException, UnsupportedOperationException, IOException { SubmitSM sm=new SubmitSM(); String strMessage="Pour se désinscrire du service TT ZONE, envoyez GRATUITEMENT « DTTZ » "; String utf8 = new String(strMessage.getBytes("UTF-8")); UCS2Encoding uc = UCS2Encoding.getInstance(true); sm.setDataCoding(2); sm.setMessageText(utf8); System.out.println(sm.getMessageText()); } }' – user2888996 Mar 21 '14 at 12:03
  • i put that as Que. as title "Encode french character in Java over smpp" – user2888996 Mar 21 '14 at 12:11