我還是用不出來呢,幫我解惑一下,例如:(紅色背景是兩段程式差異處)
測試程式:http://users10.jabry.com/jatan1985/Java/TextTransfer.java
====Code Start====
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bs = "測".getBytes();
baos.write(ESC);
baos.write("[1;33;41m".getBytes());
baos.write(bs);
baos.write(ESC);
baos.write("[m".getBytes());
String testStr = new String(baos.toByteArray()); // , "big5");
// 複製到剪貼簿
textTransfer.setClipboardContents(testStr);
====Code End====
產生:測
但是:
====Code Start====
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bs = "測".getBytes();
baos.write(ESC);
baos.write("[1;33;41m".getBytes());
baos.write(bs[0]);
baos.write(ESC);
baos.write("[;41m".getBytes());
baos.write(bs[1]);
baos.write(ESC);
baos.write("[m".getBytes());
String testStr = new String(baos.toByteArray()); // , "big5");
// 複製到剪貼簿
textTransfer.setClipboardContents(testStr);
====Code End====
預期是:測
卻產生:?[;41m?[m
也就是bs[0]、bs[1]把後面的ESC吃掉了
是否是因為我忽略了什麼東西!?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.229.169
※ 編輯: htx9 來自: 59.126.229.169 (07/29 14:17)
→
07/30 02:54, , 1F
07/30 02:54, 1F
→
07/30 10:06, , 2F
07/30 10:06, 2F
→
07/30 10:07, , 3F
07/30 10:07, 3F
→
07/30 11:49, , 4F
07/30 11:49, 4F
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):
問題
0
2