相关疑难解决方法(0)

有效地替换字符串中的所有重音字符?

对于一个穷人在客户端实现近似校正正确的排序,我需要一个JavaScript函数来在字符串中进行有效的单个字符替换.

这就是我的意思(请注意,这适用于德语文本,其他语言的排序方式不同):

native sorting gets it wrong: a b c o u z ä ö ü
collation-correct would be:   a ä b c o ö u ü z

基本上,我需要将所有出现的给定字符串的"ä"替换为"a"(依此类推).这样,本机排序的结果将非常接近用户期望的结果(或数据库将返回的内容).

其他语言有这样的设施:Python提供str.translate(),在Perl中tr/…/…/,XPath有一个函数translate(),ColdFusion有ReplaceList().但是JavaScript呢?

这就是我现在所拥有的.

// s would be a rather short string (something like 
// 200 characters at max, most of the time much less)
function makeSortString(s) {
  var translate = {
    "ä": "a", "ö": "o", "ü": …
Run Code Online (Sandbox Code Playgroud)

javascript sorting string collation

108
推荐指数
12
解决办法
11万
查看次数

获得可信的div文本时保留换行符

我想将文本保存在一个被pre格式化的contenteditable div中.我如何获得pre文本的形式而不是文本的位置\n\r省略?

$('#save').click(function(e) {
    var id = "board_code";
    var ce = $("<pre />").html($("#" + id).html());
        if ($.browser.webkit)
          ce.find("div").replaceWith(function() { return "\n" + this.innerHTML; });
        if ($.browser.msie)
          ce.find("p").replaceWith(function() { return this.innerHTML + "<br>"; });
        if ($.browser.mozilla || $.browser.opera || $.browser.msie)
          ce.find("br").replaceWith("\n");

        alert( ce.text() );
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/AD5q7/10/这不起作用

尝试字符串为contenteditable div

更新:通过键入来尝试字符串.粘贴字符串时可能没有问题.

1

abc def

    gh  i

jkl
Run Code Online (Sandbox Code Playgroud)

2

#include<iostream.h>
#include<conio.h>

int main(){
    int grade, passingMark=75;

    cout<<"Hi there, please enter your mark: ";
    cin>>grade; …
Run Code Online (Sandbox Code Playgroud)

html dom

5
推荐指数
1
解决办法
1042
查看次数

标签 统计

collation ×1

dom ×1

html ×1

javascript ×1

sorting ×1

string ×1