首页 \ 问答 \ 是否可以在Java中动态生成Unicode字符?(Is it possible to dynamically generate Unicode characters in Java? [duplicate])

是否可以在Java中动态生成Unicode字符?(Is it possible to dynamically generate Unicode characters in Java? [duplicate])

这个问题在这里已有答案:

基本上,我想在System.out.println行中使用Unicode符号,但这些Unicode字符需要动态生成。

例如,取符号U+2074U+2075U+2076 ,它们分别返回x^4x^5x^6 。 要用Java打印它我会使用\u2074\u2075\u2076 ,但如果我想根据另一个值生成它们(即\u207x ,其中x是变量)怎么办?

如果我使用PHP,我会使用变量变量 ,这将非常方便。

我甚至考虑使用hack如将u207保存为String,对x的值进行计算并将此值附加到字符串,但是在字符串中引入\符号时会出现问题:

String unicodeBase = "u207";
// I do something to get a value for x
String unicodeChar = "u207" + x;
System.out.println("\unicodeChar");

如果我这样做,我得到一个illegal unicode escape错误,这是预期的。 但是,如果我转义\符号,那么输出是一个未处理的字符串:

System.out.println("\\unicodeChar");

这将返回字符串unicodeChar

那么,是否可以在Java中动态生成Unicode字符?


This question already has an answer here:

Basically, I would like to use Unicode symbols in my System.out.println lines, but these Unicode characters would need to be dynamically generated.

For example, take symbols U+2074, U+2075 and U+2076, which return, respectively, x^4, x^5 and x^6. To print them in Java I would use \u2074, \u2075 and \u2076, but what if I want to generate them based on another value (i.e. \u207x where x is a variable)?

If I were using PHP, i would use variable variables for this which would be extremely handy.

I even went as far as thinking about using a hack like saving u207 as a String, making my calculations on the value of x and appending this value to the string, but then there are issues introducing the \ symbol inside a string:

String unicodeBase = "u207";
// I do something to get a value for x
String unicodeChar = "u207" + x;
System.out.println("\unicodeChar");

If i do this, I get an illegal unicode escape error, which is expected. But then, if I escape the \ symbol, then the output is a string that is not processed:

System.out.println("\\unicodeChar");

This returns the string unicodeChar.

So, is it possible to dynamically generate Unicode characters in Java?


原文:https://stackoverflow.com/questions/36182355
更新时间:2022-02-23 07:02

最满意答案

table.sort(list, function(a, b) return a[1] < b[1] end)

table.sort的第二个参数是一个排序函数。 因此,在这种情况下,我们将查看ab的第一项,并使用它进行比较。


table.sort(list, function(a, b) return a[1] < b[1] end)

The second argument to table.sort is a sorting function. So in this case we look into the first item in a and b and use that to compare.

相关问答

更多
  • Python Python(发音:[ 'paiθ(ə)n; (US) 'paiθɔn ]),是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的通用型语言,已经具有十多年的发展历史,成熟且稳定。Python 具有脚本语言中最丰富和强大的类库,足以支持绝大多数日常应用。 这种语言具有非常简捷而清晰的语法特点,适合完成各种高层任务,几乎可以在所有的操作系统中运行。 目前,基于这种语言的相关技术正在飞速的发展,用户数量急剧扩大,相关的资源非常多。 Python的Hello World程序 ...
  • Python   Python(英语发音:/ˈpaɪθən/), 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年,Python 源代码同样遵循 GPL(GNU General Public License)协议。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。常见的一种应用情形是,使用Python快速生成程序的原型(有时甚至是程序的最 ...
  • 这个怎么样? tbl = { { 'etc3', 1336 }, { 'etc2', 14477 }, { 'etc4', 1335 }, { 'etc1', 1337 }, } table.sort(tbl, function(a, b) return a[2] > b[2] end) for k,v in ipairs(tbl) do print(v[1], ' == ', v[2]) end 以这种方式组织数据使得排序更容易,并注意我只调用table.so ...
  • 你的问题很简单: names = {'John', 'Joe', 'Steve'} for names = 1, 3 do print (names) end 该代码首先声明一个名为names的全局变量。 然后,你开始一个for循环。 for循环声明一个局部变量,恰好恰好也称为names ; 变量之前已经用names定义的事实完全是无关紧要的。 在for循环中任何使用names都会引用本地名称 ,而不是全局名称。 for循环表示循环的内部部分将被调用, names = 1 ,然后是names = 2 ...
  • table.sort(list, function(a, b) return a[1] < b[1] end) table.sort的第二个参数是一个排序函数。 因此,在这种情况下,我们将查看a和b的第一项,并使用它进行比较。 table.sort(list, function(a, b) return a[1] < b[1] end) The second argument to table.sort is a sorting function. So in this case we look int ...
  • 它以不同的方式获取不同的数据:代码更改对象内部的数据。 struct Object { int val; }; void more_stuff(Object *the_data) { //the_data->val has 5 in it now. } void do_stuff(Object *the_data) { int old_val = the_data->val; the_data->val = 5; more_stuff(the_data); the_data->v ...
  • 你在“记忆中被覆盖”是什么意思? 你所做的一切都不会导致这种情况发生。 让我们一步一步看看你在做什么。 local head = nil 现在存在一个名为head的局部变量。 它的值nil 。 head = {next = head, value = "d"} 让我们把它分解为这里的操作顺序。 这相当于以下内容: do local temp = {} temp.next = head --This is still `nil` temp.value = "d" head = temp ...
  • 您的新表需要连续的整数键,并且需要将值本身作为表。 所以你想要这个订单上的东西: SortFunc = function (myTable) local t = {} for title,value in pairsByKeys(myTable) do table.insert(t, { title = title, value = value }) end myTable = t return myTable end 这假设pairsByKeys做 ...
  • 你似乎知道table.sort是如何工作的,所以你在哪里被困? 只需创建一个查找表,将优先级名称转换为整数并进行比较: priorities = {high = 2, medium = 1, low = 0} table.sort(t, function(e1, e2) return priorities[e1[2]] > priorities[e2[2]] end) You seem to know how table.sort works, so where are you stuck? Si ...
  • 正如Lua要求的man页面所描述的 ,它在路径中搜索文件。 这个路径可以在C中定义。看看这篇文章: “从C ++ / C设置全局LUA_PATH变量” require函数非常实用,可以加载.lua文件中定义的模块和库。 As decribed by the Lua require man page, it searches for the file in a path. This path can be defined in C. Have a look to this post : "Setting th ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。