欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

淺談C語(yǔ)言的字符串分割

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

說(shuō)起來(lái)很有意思,自認(rèn)為對(duì)C語(yǔ)言理解得還是比較深刻的。但居然到今天才知道有個(gè)strtok函數(shù),試用了一下突然感慨以前做了多少重復(fù)勞動(dòng)。每次需要解析配置文件,每次需要分割字符串,居然都是自己去分割字符串,既累人又容易出錯(cuò)。感概技術(shù)學(xué)得不夠全面啊!這里引用一段strtok用法:

The strtok() function returns a pointer to the next "token" in str1, where str2 contains the delimiters that determine the token. strtok() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should have str1 point to the string to be tokenized. All calls after this should have str1 be NULL.

For example:

char str[] = "now # is the time for all # good men to come to the # aid of their country"; 
  char delims[] = "#"; 
  char *result = NULL; 
  result = strtok( str, delims ); 
  while( result != NULL ) { 
    printf( "result is \"%s\"\n", result ); 
    result = strtok( NULL, delims ); 
  }       
/* 何問(wèn)起 hovertree.com */

The above code will display the following output: 

result is "now " 

result is " is the time for all " 

result is " good men to come to the " 

result is " aid of their country" 

這個(gè)函數(shù)跟編譯器中的詞法分析很像,在以后的文本處理中,會(huì)解決很多問(wèn)題??磥?lái)我有必要系統(tǒng)的學(xué)習(xí)下C的庫(kù)函數(shù),而不僅僅是死扎在語(yǔ)法和一些算法技巧上面。這樣在平常的工作中才能事半功倍。

使用這個(gè)函數(shù),形如下面的配置文件就非常容易解析:

id1 value1 value2 value3

id2 value1 value2 value3

...

使用這個(gè)函數(shù),分割字符串就更加方便了,例如下面待分割的字符串:

12|2345|asld|alsfalskd

只要讀取待處理的數(shù)據(jù),然后調(diào)用四次strtok就能夠解析出每行的值,以前我一般不是自己解析就是用sscanf,但是strtok更加合適,也更加啊靈活!

以上這篇淺談C語(yǔ)言的字符串分割就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持我們。

上一篇:C++中宏的使用問(wèn)題詳解

欄    目:C語(yǔ)言

下一篇:C++中的delete不會(huì)將操作數(shù)置0

本文標(biāo)題:淺談C語(yǔ)言的字符串分割

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2279.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有