Página 1 de 1

Devide String

Publicado: 02 Oct 2019 09:13
por sendai
Hello i am posted in IR but no receiving response yet.

i have this code to separate the string is there any other ways to make it short or even simple?


example string is: x = "CAR-2015*TOYOTA|VIOS"

nPipe = String.Find(x, "-", 1, false);
local sTemp = String.Mid(x, nPipe+1, -1);
local Type = String.Left(x, nPipe-1);

nPipe1 = String.Find(sTemp, "*", 1, false);
local sTemp1 = String.Mid(sTemp, nPipe1+1, -1);
local yModel = String.Left(sTemp, nPipe1-1);

local nTemp = String.Find(sTemp1, "|", 1, false);
local carBrand = String.Mid(sTemp1, nTemp+1, -1);
local carName = String.Left(sTemp1, nTemp-1);


Input.SetText("Input1", Type)
Input.SetText("Input2", yModel)
Input.SetText("Input3", carName)
Input.SetText("Input4", carBrand)

Output:

Input1 = CAR
Input2 = 2015
Input3 = TOYOTA
Input4 = VIOS

i am very limited on the code above, if you guys have more simple ways very much appreciated if you can share it to me. thank you.

Re: Devide String

Publicado: 02 Oct 2019 09:44
por Pabloko

Re: Devide String

Publicado: 02 Oct 2019 11:38
por sendai
sorry pabloko but cant understand it.. :sorry:
i dont know how to call it...

Re: Devide String

Publicado: 02 Oct 2019 12:05
por NicolasG
function DelimitedStringToTable(DelimitedString, Delimiter)
	tbReturn = {};
	local strWorking;
	local nPos = nil;
	local strData;
	local nTableIndex = 1;
	local nDelimiterLength = String.Length(Delimiter);
	
	if(nDelimiterLength < 1)then
		tbReturn[nTableIndex] = DelimitedString;
		return tbReturn;
	end
	
	strWorking = DelimitedString;
	nPos = String.Find(strWorking,Delimiter);
	while(nPos ~= -1)do
		strData = String.Left(strWorking,nPos-1);
		tbReturn[nTableIndex] = strData;
		nTableIndex = nTableIndex + 1;
		local nLength = String.Length(strWorking);
		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
		nPos = String.Find(strWorking,Delimiter);
	end
	if(strWorking ~= "")then
		tbReturn[nTableIndex] = strWorking;
	end
	
	return tbReturn;
end

local string = ("U|MOM|LIKE|MAH_DICK");

for _, string in pairs(DelimitedStringToTable(string, "|"))do
Dialog.Message("penispenispenis", string);
end


probablemente poner string no sea buena idea... :gtfo-1414026923:

Re: Devide String

Publicado: 02 Oct 2019 12:15
por sendai
@NikolasG thank you...