te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>What is the inverse function for `codepoint` in Julia? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is the inverse function for `codepoint` in Julia? - Stack Overflow

programmeradmin3浏览0评论

Julia has a function codepoint which converts from "character" to unicode codepoint value, aka UInt32. For ASCII text, this will be a value smaller than 255.

It can be used to convert a String containing many Chars (unicode codepoints) to an array of integer values.

How does one convert in the other direction? For example, if I have some numerical values (eg UInt8 values) how do I convert one of these values to a String?

There may be two paths to do this.

  • Convert UInt8 to Char (32 bits in Julia) and then convert many Char to String?
  • Convert UInt8 to String and then concatenate many length 1 strings into a larger String?

Julia has a function codepoint which converts from "character" to unicode codepoint value, aka UInt32. For ASCII text, this will be a value smaller than 255.

It can be used to convert a String containing many Chars (unicode codepoints) to an array of integer values.

How does one convert in the other direction? For example, if I have some numerical values (eg UInt8 values) how do I convert one of these values to a String?

There may be two paths to do this.

  • Convert UInt8 to Char (32 bits in Julia) and then convert many Char to String?
  • Convert UInt8 to String and then concatenate many length 1 strings into a larger String?
Share Improve this question asked 2 days ago user2138149user2138149 17.1k30 gold badges145 silver badges287 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

If you have UInt32, you can convert to Char and then String.

julia> codepoint.(collect("xyë"))
3-element Vector{UInt32}:
 0x00000078
 0x00000079
 0x000000eb

julia> String(Char.(ans))
"xyë"

If you have UInt8, you can go directly to String.

julia> UInt8.(codeunits("xyë"))
4-element Vector{UInt8}:
 0x78
 0x79
 0xc3
 0xab

julia> String(ans)
"xyë"

Julia prior to version 0.7 used to have methods for handling non-UTF-8 strings, but that functionality was removed from the language and given to packages to implement. The official documentation mentions LegacyStrings.jl to emulate functions like utf32, which will convert a Vector{UInt32} to a UTF32String for you, and from there you can convert it to a String:

using LegacyStrings

hello = "Hello, 
发布评论

评论列表(0)

  1. 暂无评论