作者: 苏鑫的博客 | 来源:发表于2017-09-26 21:45 被阅读0次
#include<stdio.h>

#define MAXSTRSIZE 255
#define True 1
#define False 0
typedef int bool;
typedef unsigned char String[MAXSTRSIZE+1];
void StrAssign(String,unsigned char []);
void StrShow(String);
int StrLength(String);
void StrCopy(String,String);
void SubString(String,String,int,int);
int StrCompare(String,String);
bool StrEmpty(String);
void Index(String,String,int);


void StrAssign(String s,unsigned char chars[]){
    int i = 0;
    while(chars[i]!='\0'){
        s[i] = chars[i];
        i++;
        
        }
    }
bool StrEmpty(String s){
    if(s[0]=='\0'){
        return True;
        }else{
        return False;   
        }
    }
void StrCopy(String t,String s){
    int i = 0;
    while(s[i]!='\0'){
        t[i] = s[i];
        i++;
        }
    }
int StrLength(String s){
    int i = 0;
    while(s[i]!='\0'){
        i++;
        }
    return i;
    }
int StrCompare(String s,String t){
    if(!StrEmpty(s)&&!StrEmpty(s)){
        if(StrLength(s)==StrLength(t)){
            int i = 0;
            while(s[i]!='\0'&&t[i]!='\0'){
                if(s[i]!=t[i])break;
                i++;
                }
            return 0;
            }else{
            return StrLength(s)-StrLength(t);   
            }
        }
        return -1;
    }
void SubString(String sub,String s,int pos,int len){
    int i = 0;
    while(s[pos]!='\0'&&len>0){
        sub[i++] = s[pos++];
        len--;
        }
    }
void Index(String s,String sub,int pos){
    if(1<=pos||pos<=StrLength(s)){
        int i = 0;
        while(sub[i]!='\0'){
            if(s[pos++]!=sub[i++])break;
            }
        if(i==StrLength(sub)){
            printf("true");
            }
        }
    }
void StrShow(String s){
    if(s){
        printf("%s\n",s);
        }
    }
    
int main(){
    String str;
    unsigned char c[]= "hello world!";
    StrAssign(str,c);
    StrShow(str);
    String t;
    StrCopy(t,str);
    StrShow(t);
    String sub;
    SubString(sub,str,6,5);
    StrShow(sub);
    Index(str,sub,6);
    
    }

相关文章

  • 串手串

    某多买的手工材料到了,晚饭后回到家,开始串手串。 之前在老家在店里买的石榴石手串200多,有点紧,勒胳膊。 想着买...

  • 糖葫芦

    糖葫芦啊,糖葫芦, 串一串啊,串一串, 五个串一串, 味道酸又甜。

  • 日日行

    一串串的星月隐了,一串串的太阳升起来;一串串的日子里,和着一串串的柴米油盐;一串串的笑声后,或躲着一串串...

  • 模式匹配中Brute-Force与KMP算法关键提取

    模式匹配是串结构的一种操作方法,用于串的匹配。待匹配串称为主串(也叫目标串),执行串称为子串(也叫模式串)。模式匹...

  • iOS中的NSString与NSMutableString

    字符串的创建 字符串读写 字符串的比较 字符串的搜索 字符串截取 字符串替换 字符串与路径 字符串转换 NSMut...

  • Javascript知识点整合

    字符串 单行字符串: ‘字符串’或“字符串” 多行字符串: `多行字符串` 字符串操作: 字符串连接‘+’号 长度...

  • DS串应用--串替换

    题目描述 给出主串、模式串、替换串,用KMP算法找出模式串在主串的位置,然后用替换串的字符替换掉模式串 本题只考虑...

  • Go 关于串的三个经典案例

    子串查找 介绍 子串查找,也可以成为字符串查找。其中有两个字符串,分为主串和子串(模式串)。在主串中查找是否含有子...

  • php 字符串常见方法汇总

    字符串拼接 字符串检索 字符串截取 字符串替换 字符串大小写转化 字符串转数组 字符串格式化

  • jq的字符串操作

    字符串拼接 字符串长度 子串 split trim 子串替换

网友评论

      本文标题:

      本文链接:https://www.haomeiwen.com/subject/ribeextx.html