zoukankan      html  css  js  c++  java
  • C语言一些常见的操作字符串方法

    // 首字母大写
    for(int i=0;(c=string[i])!='';i++)      //  字符串碰到结束   C知识
    {
        if (c==' ') {
            printf("%c",c),
            word=0;
        }else if (word==0)
        {
            word=1;
            if (c>=97&&c<122) {     //转换ASCII
                c=c-32;
            }
            num++;
            printf("%c",c);
        }else if (word==1){
            printf("%c",c);
        }
    }
    //  去空格
    char s1[100];
    printf("请输入一串字符串:
    ");
    scanf("%s",array);
    int count=0;
    char s2[100];
    for (int i = 0; i<s1.length; i++) {
        if(s1[i]!=' '){
            s2[count]=s1[i];
            count++;
        }
    }
    
    // 求最大字符串  ,
    
    for (int i = 0;i<=strlen(s);i++) {
        if(s[i]!=' '){count++;}
        if (s[i]==' '||s[i]==''){
            if(maxLen<count){maxLen = count;maxindex = i-maxLen;
            }
            count=0;
            }
        if(maxlen<count){
            maxLen=count;maxindex=i-maxLen+1;
        }
    }
    
    // 字符串反转,
    
    unsigned int len = sizeof(str);
    char temp[len];
    for(int i=0;i<len;i++){
        int a = len-i-2;
        temp[i]=str[a];
        if(i==len-1){
            temp[i] = str[i];
        }
    }
    // 求最大公共字符串
    
    void maxPublicString(char *s1,char *s2){
        unsigned long s1len = strlen(s1);
        unsigned long s2len = strlen(s2);
        int index = 0 ,count = 0;
        for(int i = 0; i<s1len ; i++)
        {
            for(int j = 0; j<s2len; j++){
                if(s1[i]==s2[j]){
                    for(int k = 1 ;s1[i+k]==s2[j+k] && s2[j+k]!='' && s1[i+k]!='' ;k++){
                        if(k>count){
                            count = k;//公共字符数
                            index = i;//下标
                        }
                    }
                }
            }
        }
        if(count == 0){
            printf("没找到最大公共字符串
    ");
        }
        else{
            printf("最长公共字符串是:");
            for(int i = 0 ; i<=count; i++){
                printf("%c",s1[index+i]);
            }
        }
        printf("
    ");
    }
  • 相关阅读:
    初识ambari
    MySQL Split 函数
    行存储和列存储
    Hbase安装和错误
    mysql 常用自定义函数解析
    mysq l错误Table ‘./mysql/proc’ is marked as crashed and should be repaired
    MySql提示:The server quit without updating PID file(…)失败
    mysql 自定义函数
    hive 调优总结
    [css] line boxes
  • 原文地址:https://www.cnblogs.com/qls1992/p/5325207.html
Copyright © 2011-2022 走看看