java,lua,c++三种语言的分割字符串

java 中分割字符串,

public class StringSplit {
    public static void main(String[] args) {
        String sourceStr = "1,2,3,4,5";
        String[] sourceStrArray = sourceStr.split(",");
        for (int i = 0; i < sourceStrArray.length; i++) {
            //System.out.print(sourceStrArray[i]);
        }


        int maxSplit = 3;
        sourceStrArray = sourceStr.split(",", maxSplit);
        for (int i = 0; i < sourceStrArray.length; i++) {
            System.out.println(sourceStrArray[i]);
        }
    }
}

lua当中分割字符串,

 

function FightMapConfig:parserMapTileConfig(sValue)
local str_v = sValue;
str_v = string.gsub(str_v, " ", "");
str_v = string.gsub(str_v, "\n", "");
str_v = string.gsub(str_v, "\r", "");
str_v = string.gsub(str_v, " ", "");


self.tileMapDef = str_v;
--print(self.tileMapDef);

local str_spl = str_v:split(",");
local index = 1;
for i=1, 9 do
for j=1, 9 do
self.tileMap_Table2[i][j] = str_spl[index];
index = index + 1;
end
end
end

 

 

c++中进行分割的方法

 

#include  
#include  

int main () 
{ 
	char str[] ="a,b,c,d*e"; 
	const char * split = ","; 
	char * p; 
	p = strtok (str, split); 

	while(p!=NULL) { 
		printf ("%s\n", p); 
		p = strtok(NULL, split); 
	} 

	getchar(); 
	return 0; 

} 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(c++,lua,java类,java,+,c++,+lua,分割字符)