Refference: http://blog.chinaunix.net/u1/56388/showart_2059483.html
函數名: stpcpy 功 能: 拷貝一個字符串到另一個 用 法: char *stpcpy(char *destin, char *source); 程序例: #include <stdio.h> #include <string.h> int main(void) { char string[10]; char *str1 = "abcdefghi"; stpcpy(string, str1); printf("%s/n", string); return 0; } 函數名: strcat 功 能: 字符串拼接函數 用 法: char *strcat(char *destin, char *source); 程序例: #include <string.h> #include <stdio.h> int main(void) { char destination[25]; char *blank = " ", *c = "C++", *Borland = "Borland"; strcpy(destination, Borland); strcat(destination, blank); strcat(destination, c); printf("%s/n", destination); return 0; } 函數名: strchr 功 能: 在一個串中查找給定字符的第一個匹配之處/ 用 法: char *strchr(char *str, char c); 程序例: #include <string.h> #include <stdio.h> int main(void) { char string[15]; char *ptr, c = 'r'; strcpy(string, "This is a string"); ptr = strchr(string, c); if (ptr) printf("The character %c is at position: %d/n", c, ptr-string); else printf("The character was not found/n"); return 0; } 函數名: strcmp 功 能: 串比較 用 法: int strcmp(char *str1, char *str2); 看Asic碼,str1>str2,返回值 > 0;兩串相等,返回0 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; int ptr; ptr = strcmp(buf2, buf1); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); else printf("buffer 2 is less than buffer 1/n"); ptr = strcmp(buf2, buf3); if (ptr > 0) printf("buffer 2 is greater than buffer 3/n"); else printf("buffer 2 is less than buffer 3/n"); return 0; } 函數名: strncmpi 功 能: 將一個串中的一部分與另一個串比較, 不管大小寫 用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBB", *buf2 = "bbb"; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); if (ptr < 0) printf("buffer 2 is less than buffer 1/n"); if (ptr == 0) printf("buffer 2 equals buffer 1/n"); return 0; } 函數名: strcpy 功 能: 串拷貝 用 法: char *strcpy(char *str1, char *str2); 程序例: #include <stdio.h> #include <string.h> int main(void) { char string[10]; char *str1 = "abcdefghi"; strcpy(string, str1); printf("%s/n", string); return 0; } 函數名: strcspn 功 能: 在串中查找第一個給定字符集內容的段 用 法: int strcspn(char *str1, char *str2); 程序例: #include <stdio.h> #include <string.h> #include <alloc.h> int main(void) { char *string1 = "1234567890"; char *string2 = "747DC8"; int length; length = strcspn(string1, string2); printf("Character where strings intersect is at position %d/n", length); return 0; } 函數名: strdup 功 能: 將串拷貝到新建的位置處 用 法: char *strdup(char *str); 程序例: #include <stdio.h> #include <string.h> #include <alloc.h> int main(void) { char *dup_str, *string = "abcde"; dup_str = strdup(string); printf("%s/n", dup_str); free(dup_str); return 0; } 函數名: stricmp 功 能: 以大小寫不敏感方式比較兩個串 用 法: int stricmp(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBB", *buf2 = "bbb"; int ptr; ptr = stricmp(buf2, buf1); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); if (ptr < 0) printf("buffer 2 is less than buffer 1/n"); if (ptr == 0) printf("buffer 2 equals buffer 1/n"); return 0; } 函數名: strerror 功 能: 返回指向錯誤信息字符串的指針 用 法: char *strerror(int errnum); 程序例: #include <stdio.h> #include <errno.h> int main(void) { char *buffer; buffer = strerror(errno); printf("Error: %s/n", buffer); return 0; } 函數名: strcmpi 功 能: 將一個串與另一個比較, 不管大小寫 用 法: int strcmpi(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBB", *buf2 = "bbb"; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); if (ptr < 0) printf("buffer 2 is less than buffer 1/n"); if (ptr == 0) printf("buffer 2 equals buffer 1/n"); return 0; } 函數名: strncmp 功 能: 串比較 用 法: int strncmp(char *str1, char *str2, int maxlen); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc"; int ptr; ptr = strncmp(buf2,buf1,3); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); else printf("buffer 2 is less than buffer 1/n"); ptr = strncmp(buf2,buf3,3); if (ptr > 0) printf("buffer 2 is greater than buffer 3/n"); else printf("buffer 2 is less than buffer 3/n"); return(0); } 函數名: strncmpi 功 能: 把串中的一部分與另一串中的一部分比較, 不管大小寫 用 法: int strncmpi(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBBccc", *buf2 = "bbbccc"; int ptr; ptr = strncmpi(buf2,buf1,3); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); if (ptr < 0) printf("buffer 2 is less than buffer 1/n"); if (ptr == 0) printf("buffer 2 equals buffer 1/n"); return 0; } 函數名: strncpy 功 能: 串拷貝 用 法: char *strncpy(char *destin, char *source, int maxlen); 程序例: #include <stdio.h> #include <string.h> int main(void) { char string[10]; char *str1 = "abcdefghi"; strncpy(string, str1, 3); string[3] = '/0'; printf("%s/n", string); return 0; } 函數名: strnicmp 功 能: 不注重大小寫地比較兩個串 用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBBccc", *buf2 = "bbbccc"; int ptr; ptr = strnicmp(buf2, buf1, 3); if (ptr > 0) printf("buffer 2 is greater than buffer 1/n"); if (ptr < 0) printf("buffer 2 is less than buffer 1/n"); if (ptr == 0) printf("buffer 2 equals buffer 1/n"); return 0; } 函數名: strnset 功 能: 將一個串中的所有字符都設爲指定字符 用 法: char *strnset(char *str, char ch, unsigned n); 程序例: #include <stdio.h> #include <string.h> int main(void) { char *string = "abcdefghijklmnopqrstuvwxyz"; char letter = 'x'; printf("string before strnset: %s/n", string); strnset(string, letter, 13); printf("string after strnset: %s/n", string); return 0; } 函數名: strpbrk 功 能: 在串中查找給定字符集中的字符 用 法: char *strpbrk(char *str1, char *str2); 程序例: #include <stdio.h> #include <string.h> int main(void) { char *string1 = "abcdefghijklmnopqrstuvwxyz"; char *string2 = "onm"; char *ptr; ptr = strpbrk(string1, string2); if (ptr) printf("strpbrk found first character: %c/n", *ptr); else printf("strpbrk didn't find character in set/n"); return 0; } 函數名: strrchr 功 能: 在串中查找指定字符的最後一個出現 用 法: char *strrchr(char *str, char c); 程序例: #include <string.h> #include <stdio.h> int main(void) { char string[15]; char *ptr, c = 'r'; strcpy(string, "This is a string"); ptr = strrchr(string, c); if (ptr) printf("The character %c is at position: %d/n", c, ptr-string); else printf("The character was not found/n"); return 0; } 函數名: strrev 功 能: 串倒轉 用 法: char *strrev(char *str); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *forward = "string"; printf("Before strrev(): %s/n", forward); strrev(forward); printf("After strrev(): %s/n", forward); return 0; } 函數名: strset 功 能: 將一個串中的所有字符都設爲指定字符 用 法: char *strset(char *str, char c); 程序例: #include <stdio.h> #include <string.h> int main(void) { char string[10] = "123456789"; char symbol = 'c'; printf("Before strset(): %s/n", string); strset(string, symbol); printf("After strset(): %s/n", string); return 0; } 函數名: strspn 功 能: 在串中查找指定字符集的子集的第一次出現 用 法: int strspn(char *str1, char *str2); 程序例: #include <stdio.h> #include <string.h> #include <alloc.h> int main(void) { char *string1 = "1234567890"; char *string2 = "123DC8"; int length; length = strspn(string1, string2); printf("Character where strings differ is at position %d/n", length); return 0; } 函數名: strstr 功 能: 在串中查找指定字符串的第一次出現 用 法: char *strstr(char *str1, char *str2); 程序例: #include <stdio.h> #include <string.h> int main(void) { char *str1 = "Borland International", *str2 = "nation", *ptr; ptr = strstr(str1, str2); printf("The substring is: %s/n", ptr); return 0; } 函數名: strtod 功 能: 將字符串轉換爲double型值 用 法: double strtod(char *str, char **endptr); 程序例: #include <stdio.h> #include <stdlib.h> int main(void) { char input[80], *endptr; double value; printf("Enter a floating point number:"); gets(input); value = strtod(input, &endptr); printf("The string is %s the number is %lf/n", input, value); return 0; } 函數名: strtok 功 能: 查找由在第二個串中指定的分界符分隔開的單詞 用 法: char *strtok(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) { char input[16] = "abc,d"; char *p; /* strtok places a NULL terminator in front of the token, if found */ p = strtok(input, ","); if (p) printf("%s/n", p); /* A second call to strtok using a NULL as the first parameter returns a pointer to the character following the token */ p = strtok(NULL, ","); if (p) printf("%s/n", p); return 0; } 函數名: strtol 功 能: 將串轉換爲長整數 用 法: long strtol(char *str, char **endptr, int base); 程序例: #include <stdlib.h> #include <stdio.h> int main(void) { char *string = "87654321", *endptr; long lnumber; /* strtol converts string to long integer */ lnumber = strtol(string, &endptr, 10); printf("string = %s long = %ld/n", string, lnumber); return 0; } 函數名: strupr 功 能: 將串中的小寫字母轉換爲大寫字母 用 法: char *strupr(char *str); 程序例: #include <stdio.h> #include <string.h> int main(void) { char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; /* converts string to upper case characters */ ptr = strupr(string); printf("%s/n", ptr); return 0; } 函數名: swab 功 能: 交換字節 用 法: void swab (char *from, char *to, int nbytes); 程序例: #include <stdlib.h> #include <stdio.h> #include <string.h> char source[15] = "rFna koBlrna d"; char target[15]; int main(void) { swab(source, target, strlen(source)); printf("This is target: %s/n", target); return 0; }
free -h total used free shared buff/cache available Mem: 125G 88G
簡介: 搶紅包是我們生活常用的社交功能, 這個功能最主要的特點就是用戶的併發請求高, 在系統設計上, 可以使用非常多的辦法來扛住用戶的高併發請求, 在本文中簡要介紹使用Redis緩存中間件來實現搶紅包算法, Redis是一個在內存中基
字符串是 Java 程序中最常用的數據結構之一。在 Java 中 String 類已經重載了"+",字符串可以直接使用"+"進行連接,也可以用StringBuilder/StringBuffer(StringBuilder是J2SE5 及以
Java 平臺提供了兩種類型的字符串操作方式:String 和 StringBuffer/StringBuilder,它們都可以儲存和操作字符串,區別如下: String 是隻讀字符串,也就意味着 String 引用的字符串內容是不能被改
1 枚舉好用嗎? 數據字典型字段,枚舉比Integer好: 限定值,只能賦值枚舉的那幾個實例,不能像Integer隨便輸,保存和查詢的時候特別有用 含義明確,使用時不需要去查數據字典 顯示值跟存儲值直接映射,不需要手動轉換,比如1在頁面上
1 概述 通道是Golang提供的一種基本類型,它可以實現在協程之間的單向通信和雙向通信、發送和接收數據、以及協程同步。 channel的本質是一個隊列,遵循先進先出原則。channel是線程安全的,在任何給定時間,一個數據被設計爲只有一
簡介 go-python Python提供了豐富的C-API。而C和Go又可以通過cgo無縫集成。所以,直接通過Golang調用libpython,就可以實現Go調Python的功能了。但是過程比較複雜,而go-python提供了針對CPy
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 之前本人在找工作面試時在Redis相關問題上可栽了跟頭。在面試前按常規套路準備了一下,比如 Redis 的常用5種數據結構,Redis持久化
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 本文要點 即將於 2020 年 9 月發佈的 Java SE 15 將引入“封印類(sealed class)”(JEP 360),並將其作
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 簡介 Spring Boot 2.2.0 版本開始引入 JUnit 5 作爲單元測試默認庫,在 Spring Boot 2.2.0 版本之前
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 編者按:作爲一個Java開發者,你是否曾爲在PyTorch上部署模型而苦惱?這篇來自AWS軟件工程師的投稿,結合實例,詳細介紹了DJL這個
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 成員方法 類成員主要包括成員變量和成員方法。 帶參數的成員方法 帶參數的成員方法可以接受用戶輸入的內容。創建帶參數的方法時定義的參數叫形式
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 要點: Deno 和 Node.js 都在基於 C/C ++ 的運行時上執行 JavaScript 以實現高性能。Deno 是單個二進制應
雲棲號資訊:【點擊查看更多行業資訊】在這裏您可以找到不同行業的第一手的上雲資訊,還在等什麼,快來! 阿里妹導讀:我們在選擇一種開發語言時會綜合考量各方面的特性,根據實際的需求適當取捨。魚和熊掌往往不可兼得,要想開發效率高,必然要犧牲性能
Java有8種基本數據類型,每種基本數據類型都提供了一種對應的包裝類型,從 Java 5 開始引入了自動裝箱/拆箱機制,使得二者可以相互轉換。 原始類型: boolean,char,byte,short,int,long,float,do