The SqString for Sequential string | Data

简介: The code in Data book (5th Edition) from the 123 page to 126 page

The code in Data book (5th Edition) from the 123 page to 126 page

typedef struct {
    char data[MaxSize]; //Stored string Character
    int length; //Stored string length
} SqString; //Sequential string type

//Generated string
void StrAssign(SqString &s, char cstr[]) {
    int i;
    for(i=0; cstr[i]!='\0'; i++) {
        s.data[i]=cstr[i];
    }
    s.length=i;  //Set string s length
}

//Destroyed string
void DestroyStr(SqString &s) {}

//Copy string
void StrCopy(SqString &s, SqString t) {
    for(int i=0; i<t.length; i++) {
        s.data[i]=t.data[i]; //Copy all character of t
    }
    s.length=t.length; //Set length of string s
}

//Judge string equality
bool StrEqual(SqString s, SqString t) {
    bool same=true;
    if(s.length!=t.length) { //When string length not equal return 0
        same=false;
    }
    else
        for(int i=0; i<s.length; i++)
            if(s.data[i]!=t.data[i]) { //When have a character not equal return false
                same=false;
                break;
            }
    return same;
}

//Get string length
int StrLength(SqString s) {
    return s.length;
}

//Connection string
SqString Concat(SqString s,SqString t) {
    SqString str;
    int i;
    str.length=s.length+t.length;
    for(i=0; i<s.length; i++)
        str.data[i]=s.data[i];
    for(i=0; i<t.length; i++)
        str.data[s.length+i]=t.data[i];
    return str;
}

//Get substring
SqString SubStr(SqString s,int i,int j) {
    int k;
    SqString str;
    str.length=0;
    if(i<=0||i>s.length||j<0||i+j-1>s.length)
        return str;
    for(k=i-1; k<i+j-1; k++)
        str.data[k-i+1]=s.data[k];
    str.length=j;
    return str;
}

//Insert substring
SqString InsStr(SqString s1,int i,SqString s2) {
    int j;
    SqString str;
    str.length=0;  //Set ser is empty string
    if(i<=0||i>s1.length+1)  //When parameters incorrect return empty string
        return str;
    for(j=0; j<i-1; j++)
        str.data[j]=s1.data[j];
    for(j=0; j<s2.length; j++)
        str.data[i+j-1]=s2.data[j];
    for(j=i-1; j<s1.length; j++)
        str.data[s2.length+j]=s1.data[j];
    str.length=s1.length+s2.length;
    return str;
}

//Delete substring
SqString DelStr(SqString s,int i,int j) {
    int k;
    SqString str;
    str.length=0;  //Set str is empty string
    if(i<=0||i>s.length||i+j>s.length+1)
        return str;  //When parameters incorrect return empty string
    for(k=0; k<i-1; k++)
        str.data[k]=s.data[k];
    for(k=i+j-1; k<s.length; k++)
        str.data[k-j]=s.data[k];
    str.length=s.length-j;
    return str;
}

//Replace substring
SqString RepStr(SqString s,int i,int j,SqString t) {
    int k;
    SqString str;  //Defined results string
    str.length=0;  //Set ser is empty string
    if(i<=0||i>s.length||i+j-1>s.length)
        return str;  //When parameters incorrect return empty string
    for(k=0; k<i-1; k++)
        str.data[k]=s.data[k];
    for(k=0; k<t.length; k++)
        str.data[i+k-1]=t.data[k];
    for(k=i+j-1; k<s.length; k++)
        str.data[t.length+k-j]=s.data[k];
    str.length=s.length-j+t.length;
    return str;
}

//Output string
void DispStr(SqString s) {
    if(s.length>0) {
        for(int i=0; i<s.length; i++)
            printf("%c",s.data[i]);
        printf("\n");
    }
}
如有侵权,请联系作者删除
目录
相关文章
|
SQL XML 存储
源码分析 There is no getter for property named '*' in 'class java.lang.String(2)
源码分析 There is no getter for property named '*' in 'class java.lang.String
234 0
源码分析 There is no getter for property named '*' in 'class java.lang.String(2)
|
SQL Java 测试技术
源码分析 There is no getter for property named '*' in 'class java.lang.String(1)
源码分析 There is no getter for property named '*' in 'class java.lang.String
469 0
源码分析 There is no getter for property named '*' in 'class java.lang.String(1)
UWP中String 转为Path Data
定义方法: Geometry PathMarkupToGeometry(string pathMarkup) { string xaml = "" + "" + pathMarkup + ""; var path = XamlReader.
1119 0
|
SQL 数据库
【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE
【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE 在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的大小会从4K以及2K字节扩展至32K字节。
1268 0
|
SQL Java
源码分析 There is no getter for property named '*' in 'class java.lang.String
版权声明:欢迎转载,请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/47122227 There is no getter for property named '*' in 'class java.lang.String',此错误之所以出现,是因为mybatis在对parameterType="String"的sql语句做了限制,假如你使用这样的条件判断时,就会出现该错误,不过今天我们来刨根问底一下。
900 0
|
Web App开发 JSON JavaScript
IE9.0或者360下js(JavaScript、jQuery)不能正确执行(加载),按F12后执行正常;Firefox下ajax的success返回数据data(json、string)无法获取
兼容问题1: 页面的分享等插件加载不全,并无法点击。 兼容问题2: IE下页面选择器(#id、.class.etc.)绑定click事件无法访问到,后台springmvc方法,也无法获取ajax的success方法返回值data。 兼容问题3: 在IE和Google下能够获取,ajax的success返回的数据data,但firefox下获取不到。 兼容问题4: 页面跳转,或
2805 0
|
XML 数据格式
The maximum string content length quota (8192) has been exceeded while reading XML data
原文: The maximum string content length quota (8192) has been exceeded while reading XML data   问题场景:在我们WCF服务发布后,我们要确保服务端以及客户端的配置文件允许合适大小的传输设置。
1349 0
Parameter \&#39; \&#39;: No size set for variable length data type: String
http://blog.163.com/pinbo_jiankun/blog/static/13354648820138245630971/
1014 0
下一篇
无影云桌面