希伯来语“URL编码”在 R 中?

发布于 2024-10-06 23:45:17 字数 803 浏览 0 评论 0原文

我已经提到了这两个函数:

?URLencode
#and
?curlEscape

我发现这两个函数都非常适合英语,但无法为希伯来语字符提供正确的翻译。

例如,这个词

我的世界

(希伯来语,和平) 应该是这样的:

%D7%A9%D7%9C%D7%95%D7%9D

但是,这两个命令都将其翻译为:

URLencode("שלום")
%f9%ec%e5%ed

您有什么建议? (我自己写的,或者有预先制作的东西)

谢谢, 塔尔

更新:我的会话信息:

> sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255   
[3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C                  
[5] LC_TIME=Hebrew_Israel.1255    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

I've been referred to both:

?URLencode
#and
?curlEscape

I see that both functions work great for English, but fail to provide with the proper translation for Hebrew characters.

For example, the word

שלום

(Peace, in Hebrew)
Should be this:

%D7%A9%D7%9C%D7%95%D7%9D

But instead, both commands translate it to:

URLencode("שלום")
%f9%ec%e5%ed

What do you suggest? (write it myself, or is there something pre-made)

Thanks,
Tal

Update: My sessionInfo:

> sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255   
[3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C                  
[5] LC_TIME=Hebrew_Israel.1255    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

獨角戲 2024-10-13 23:45:17

URLencode 和 charToRaw 似乎都适合我......

URLencode(")
[1]“%d7%a9%d7%9c%d7%95%d7%9d”

看URLencode的源码

URL编码
函数(URL,保留 = FALSE)
{
确定 <- 粘贴("[^-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz0123456789$_.+!*'(),",
如果(!保留)
";/?:@=&", "]", sep = "")
x <- strsplit(URL, "")[[1L]]
z <- grep(OK, x)
如果(长度(z)){
y <- sapply(x[z], function(x) 粘贴("%", as.character(charToRaw(x)),
sep = "", 折叠 = ""))
x[z] <- y
}
粘贴(x,折叠=“”)
}

charToRaw(")
[1] d7 a9 d7 9c d7 95 d7 9d

您使用的是哪个版本的 R?

这是我的 sessionInfo()

sessionInfo()
R版本2.10.0 (2009-10-26)
i386-pc-mingw32

区域设置:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

附加基础包:
[1] 统计图形 grDevices utils 数据集方法库

其他附件包:
[1] preprocessCore_1.8.0

通过命名空间加载(且未附加):
[1]tools_2.10.0

Both URLencode and charToRaw seem to work for me...

URLencode("שלום")
[1] "%d7%a9%d7%9c%d7%95%d7%9d"

Looking at the source code of URLencode

URLencode
function (URL, reserved = FALSE)
{
OK <- paste("[^-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz0123456789$_.+!*'(),",
if (!reserved)
";/?:@=&", "]", sep = "")
x <- strsplit(URL, "")[[1L]]
z <- grep(OK, x)
if (length(z)) {
y <- sapply(x[z], function(x) paste("%", as.character(charToRaw(x)),
sep = "", collapse = ""))
x[z] <- y
}
paste(x, collapse = "")
}

charToRaw("שלום")
[1] d7 a9 d7 9c d7 95 d7 9d

Which version of R are you using?

Here is my sessionInfo()

sessionInfo()
R version 2.10.0 (2009-10-26)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] preprocessCore_1.8.0

loaded via a namespace (and not attached):
[1] tools_2.10.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文