UITextField 计算输入的字符个数(包含中英文数字特殊符号)

+ (int)convertToInt:(NSString*)strtemp
{
    int strLength = 0;
    char *p = (char *)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
        int length = [strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding];

    for (int i = 0; i < length; i ++) {
        if (*p) {
            p ++;
            strLength ++;
        }else{
            p ++;
        }
    }

    return (strLength+1)/2;
}
时间: 2024-08-01 04:50:32

UITextField 计算输入的字符个数(包含中英文数字特殊符号)的相关文章

UITextField限制输入的字符个数。比如输入手机号时,只能是11位

- (void)setupTextField { UITextField *tf = [[UITextField alloc] init]; tf.keyboardType = UIKeyboardTypeNumberPad; tf.frame = CGRectMake(80, 80, 200, 40); tf.backgroundColor = [UIColor redColor]; [self.view addSubview:tf]; [[NSNotificationCenter defau

正则判断输入的字符(英文、数字、空格、其他)的个数

1 /** 2 * 3 * 类 描 述: 正则判断输入的字符(英文.数字.空格.其他)的个数 4 * 作 者: 赵 鹏 5 */ 6 public class RegularJudgeCharacter { 7 8 public static void main(String[] args) { 9 10 String arg = "safd415 ^&*^*^$# "; 11 12 //将string字符串转义为char数组 13 char[] charArray = arg

iOS开发--UITextField限制输入文字的个数

项目需要输入框的文字最多为4个,为了实现这个功能,在网上把资料翻遍了,没有一个能用的.后来不得不自己实现,折腾了好久,终于搞定了.小技巧分享给大家. 代码如下: static constNSInteger Max_Character_Num =4; - (IBAction)onTextFieldEditingChanged:(id)sender { NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; if

BearSkill实用方法之UITextField限制输入的字符数量

原文:http://blog.csdn.net/xiongbaoxr/article/details/51525061

[javascript] 记录一次解决输入内容控制为 【半角英数字 + 限定符号】问题的过程

还是这个小网站项目,需要控制一个输入框的可输入内容, 在此记录一下编码过程. 需求: 可输入范围: a-z A-Z 0-9 - // 短中横线 _ // 短下划线 . // 点 ' // 单引号 <input type='text' id='Target' maxlength='20' /> 想法很简单,直接在oninput里用正则匹配替换掉不需要的字符, $(function(){ $('#Target').on('input', function(){ $(this).val($(this

c语言判断是否是utf8字符串,计算字符个数

#include <stdio.h> #include <string.h> #include <stdlib.h> /**************************************************************************** Unicode符号范围 | UTF-8编码方式 (十六进制) | (二进制) 0000 0000-0000 007F:0xxxxxxx 0000 0080-0000 07FF:110xxxxx 10x

华为OJ——输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数

题目描述 输入一行字符,分别统计出包含英文字母.空格.数字和其它字符的个数. 输入描述: 输入一行字符串,可以有空格 输出描述: 统计其中英文字符,空格字符,数字字符,其他字符的个数 输入例子: 1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][ 输出例子: 26 3 10 12 <span style="font-size:18px;">import java.util.*; public class Main { pu

51.从键盘上输入任意两个数和一个运算符(+、-、*、/),根据输入的运算符对两个数计算,并输出结果

?#include<iostream> using namespace std; int main() { int x,y; char a; cout<<"please input two numbers: "<<endl; cin>>x>>y; cout<<"please input an operational character:"<<endl; cin>>a; s

7 判断输入字符个数

题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. 1 public class _007CountStringAll { 2 3 public static void main(String[] args) { 4 printCount(); 5 } 6 7 private static void printCount() { 8 while (true) { 9 Scanner scanner = new Scanner(System.in); 10 System.ou