如何在不使用第三方库的情况下转义java字符串中的unicode字符

时间:2023-01-18 00:27:05

I got a .Net project which clients would use and pass in a String. The .Net code calls a java service. Say the string is "\123"

我有一个.Net项目,客户端将使用并传入一个String。 .Net代码调用java服务。说字符串是“\ 123”

I am not as familiar with .NET as i am with Java.

我不像Java那样熟悉.NET。

Looks like C# automatically escapes the unicode \ in the string value and considers that value as "\123" itself.

看起来C#会自动转义字符串值中的unicode \并将该值视为“\ 123”本身。

When the value comes into java it becomes "S" as "\123" is a unicode value and represents "S". This is unacceptable

当值进入java时,它变为“S”,因为“\ 123”是unicode值并代表“S”。这是无法接受的

I can't use apache commons lang StringEscapeUtils due to corporate restrictions on using third party libraries. I don't have a choice here.

由于公司限制使用第三方库,我无法使用apache commons lang StringEscapeUtils。我在这里没有选择。

So how do I handle all such unicode characters in this case?

那么在这种情况下如何处理所有这些unicode字符呢?

1 个解决方案

#1


0  

You could simply escape the unicode with a double backslash:

您可以使用双反斜杠简单地转义unicode:

\\123 represents \123 as a string

\\ 123表示\ 123作为字符串

#1


0  

You could simply escape the unicode with a double backslash:

您可以使用双反斜杠简单地转义unicode:

\\123 represents \123 as a string

\\ 123表示\ 123作为字符串