---
title: "js简单算法"
author: "airendos"
date: "2012-03-31T15:54:34Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2012-03-31T15:54:34Z"
id: 1471689
url: "https://airendos.iteye.com/blog/1471689"
---

```java


var textLen = text.replace(/[^\x00-\xff]/gi,'xu').length;//字节数
textLen = textLen%2 == 0 ? textLen/2 : textLen/2+0.5;//字符数
//1字符 = 2字节


```