Question about function which defines arrays

A forum dedicated to George scripting questions
Post Reply
User avatar
ini
Posts: 131
Joined: 14 Aug 2015, 17:47
Contact:

Question about function which defines arrays

Post by ini »

Hi, I'am sorry.
I'am not goot at English


I want to make function which makes(?) arrays with string divided by divider.



Code: Select all

FUNCTION nnParse(Array,string,divider)
	LOCAL pos i workstr size
	i = 0
	pos = 1
	workstr = string
	Array[0] = 0
			IF ((CMP(workstr,"") == 0) && (CMP(divider,"") == 0) && (CMP(workstr,divider) == 0))  // 문자열이 0(공백)과 다르고, 디바이더가 0(공백) 과 다르고 문자열이 공백과 다를때 실행한다.
					if (pos = Find(workstr,divider,1)) <= 0
					i = i+1
					Array[i] = workstr
					else
						WHILE ((pos = Find(workstr,divider,1)) > 0)	// print "pos_" pos "Len_" LEN(workstr)
								IF ((pos != 1) && (pos != LEN(workstr)))		//디바이더가 첫번째가 아니면서, 디바이더가 문자열길이와같지 않을때
								i = i+1
								Array[i] = CUT(workstr,1,pos-1)
								workstr = CUT(workstr,pos+1,LEN(workstr))//print workstr
								ELSE															//디바이더가 첫번째이거나  디바이더가 문자열길이와같지 않을때
										IF (pos == 1)			//디바이더가 첫번째
											IF (pos != LEN(workstr))		//디바이더가 첫번째,디바이더가 문자열길이와같지 않을때
												i=i+1
													Array[i] = ""
												workstr = CUT(workstr,pos+1,LEN(workstr))
											ELSE 									//디바이더가 첫번째면서디바이더와 문자열길이가 같을때
												i=i+1
												Array[i] = ""
												workstr = ""
											END
										ELSE					//디바이더가 첫번째가 아니면서 문자열길이와 같을 때
											IF ((pos != 1) && (pos == LEN(workstr)))
												i=i+1
												Array[i] = CUT(workstr,1,pos-1)
												workstr =""
											end
										END
								END
						end
						IF (CMP(workstr,"") == 0)
						i = i+1
						Array[i] = workstr
						end
					END
						

				Array[i+1]= "EOS"

			END
		RETURN i
END


//===============================================================================================================================
//
//	Find
//
//	Function: find a character into a string
//            from a specified start position
//
//	Call: Find(string,car,start)
//
//	Arguments:
//		string = characters string
//		car    = character to look for
//		start  = start position in string
//
//	Return: position of character
//			0 if character does not exist
//			into string
//			-1 if invalid position
//			(negative, null or higher
//			 than string length)
//
//------------------------------------------

FUNCTION Find(string,car,start)
	LOCAL i size
	i = start
	size = LEN(string)
	
	IF ((start <= 0) || (start > size) || (CMP(car,"") == 1))
		RETURN -1
	END
	DO
		IF (CMP(CHAR(string,i),car) == 1)
			RETURN i
		END
	UNTIL ((i=i+1) > size)
	RETURN 0
END	
///////////////////////////////////////////////////////////////////////////////////////////////
FUNCTION nnParse(Array,string,divider)

the string is "a_b_c_saoidjjfi__"
the divider = "_"

nnParse(NameofArray, "a_b_c_saoidjjfi__", "_")

then This function makes arrays like this. (What I intended)

NameofArray[1] = "a"
NameofArray[2] = "b"
NameofArray[3] = "c"
NameofArray[4] = "saoidjjfi"
NameofArray[5] = " " (because there are two underbar)
NameofArray[6] = "EOS" (END of String)

and the function returns "5"

this is what i want to make.


But, when I use function,
'Array[num]' is defined with saperated stirings instead of 'NameofArray[num]' like this

Array[1] = "a"
Array[2] = "b"
Array[3] = "c"
Array[4] = "saoidjjfi"
Array[5] = " "
Array[6] = "EOS"

So, I'm using the way to redifine after using function now.


For j =1 to nnParse(NameofArray, "a_b_c_saoidjjfi__", "_")
NameofArray[j] = Array[j]
end

so It doesn't matter, but I'm wondering if there is way to making array with 'name of array' I inputted in function.....
e-mail : ini@7ini.com twitter : @Ain_is_
-----------------------------------------
TVPaint 11 PRO STD (11.7.0 - 64bits) on
AMD Ryzen9 5950x, 3080 &2080ti, 128GB ram, Windows10, Cintiq 27 Pro (DTH-271)
TVPaint 11 PRO WIBU (11.5.1 - 64bits) on
Cintiq Mobile Studio Pro 13 (DTH-W1321H), Windows10
Post Reply