javascript - first letter up all uppercase words in string data with jquery - Stack Overflow

my string data as as follow.var HmtlStr = "<span>My names is <u>KERBEROS<u>. AG

my string data as as follow.

var HmtlStr = "<span>My names is <u>KERBEROS</u>. AGE: 29, my eyes <b>BROWN</b>.</span"

result must be like this which i want;

<span>My names is <u>Kerberos</u>. Age: 29, my eyes <b>Brown</b>.</span

thank you very much for your help, already now.

my string data as as follow.

var HmtlStr = "<span>My names is <u>KERBEROS</u>. AGE: 29, my eyes <b>BROWN</b>.</span"

result must be like this which i want;

<span>My names is <u>Kerberos</u>. Age: 29, my eyes <b>Brown</b>.</span

thank you very much for your help, already now.

Share asked Oct 29, 2010 at 22:27 KerberosKerberos 1,2566 gold badges25 silver badges50 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Perhaps the CSS text-transform: capitalize would work?

Use a function in a replace to change the strings:

HmtlStr = HmtlStr.replace(
  /([A-Z])([A-Z]+)/g,
  function(a,m1,m2) {
    return m1 + m2.toLowerCase();
  }
);

Edit:

The built in toLowerCase method handles most characters, you just have to include them in the set in the regular expression ([A-ZÖİŞÜĞÇ]) so that they are handled. To handle the few characters that the built in method doesn't cope with, you can make a function that replaces those first:

function localLowerCase(str) {
  str = str.replace(
    /İ/g,
    function(m){
      var i = "İ".indexOf(m);
      return i != -1 ? "ı"[i] : m;
    }
  );
  return str.toLowerCase();
}

You can easily add more characters for the function to handle by adding them in the /İ/ pattern, the "İ" string and the replacement in the "ı" string.

Try this one:

   'apple cat dog stack overflow'.replace(/(\b)([a-zA-Z])/g,
       function(firstLetter){
          return   firstLetter.toUpperCase();
       })

:)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742402748a4437239.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信