1 Star 2 Fork 1

Robot_Steve / LightweightCString

加入 Gitee
与超过 800 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README.md

LightweighCString

Introduction:

A String library implemented in C
It allows you to easily manipulate strings
(I really don't like the string Library of C language. Is there anyone like me?)

Explain:

This is a library I wrote when developing Tranquility programming language. The reason is that it's too troublesome to use C string when developing programming language
I think the operation is very simple. A few sentences of code can solve the problem of operating strings. Personally, it is very convenient :)

Main functions of the Library:

  • Initialize String
  • Add new string to string
  • Add new char to string
  • Replace the specified content in the original string with another string
  • Used to locate a string in the original data to determine its location
  • Clear the contents of the String class
  • Get string data
  • Get string length


Some Example:

  1. Realize a simple storage and reading
#include "LCString.h"

int main(){
        string a = initStr();
        a = addStr(a, "hello, world"); // Add a string

        // Stdio has been introduced into the String library,
        // so you don't need to reference it anymore
	// Get the string in a, Print the contents of a
        printf("%s\n", getData(a));
	
	// Small programs don't need to add this
	// But the big program must add this!!!
	free(a);
	
	return 0;
}



2. Replace the contents of the string

#include "LCString.h"

int main(){
        string a = initStr();
        a = addStr(a, "aaabbbccc"); // Add a string

        // Replace the contents of the string
        // Reassign the return value to a
        a = replace(a, "a", ""); 

        // Get the string in a, Print the contents of a
        printf("%s\n", getData(a));
	
	// Small programs don't need to add this
	// But the big program must add this!!!
	free(a);
	
	return 0;
}



3. Find string position

#include "LCString.h"

int main(){
        string a = initStr();
        a = addStr(a, "abcd1edguowgue"); // Add a string
        
        // Find string position
        // Note: the index of the first letter in the string is 0
        int pos = find(a, "1");

        // Print location
        printf("%d\n", pos);
	
	// Small programs don't need to add this
	// But the big program must add this!!!
	free(a);
	
	return 0;
}



4. Get string length

#include "LCString.h"

int main(){
        string a = initStr();
        a = addStr(a, "abcd1edguowgue"); // Add a string
        
        // Get the string length
        int length = len(a);

        // Print the length
        printf("%d\n", length);
	
	// Small programs don't need to add this
	// But the big program must add this!!!
	free(a);
	
	return 0;
}



Feedback:

If you have any questions, you can send an email to robotsteve@163.com

仓库评论 ( 0 )

你可以在登录后,发表评论

简介

一个使用C语言编写的轻量化的String库 展开 收起
C
GPL-2.0
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/robot-steve/LightweightCString.git
git@gitee.com:robot-steve/LightweightCString.git
robot-steve
LightweightCString
LightweightCString
main

搜索帮助