cancel
Showing results for 
Search instead for 
Did you mean: 

Split the string

former_member187270
Participant

Hi Experts,

I am looking for split functionality. Is there any keyword to split the string.

Thanks,

Quddus.

View Entire Topic
Rihards
Explorer
0 Kudos

hey, I found this piece somewhere but it works.

try to execute below code

import AP.Common.GDT; //for split	

        var deliveryLocalString = "87676767, 87676766, 87676765, 87676764, 87676763, 87676762";
	var deliveryStringTable : collectionof DataType::LANGUAGEINDEPENDENT_EXTENDED_Text; //if it doesn't work try to replace with a string or LongText
        //       ^ this is the FINAL result of split!
	//****************************************************
	//first we have a very long string, which we have to split to create a table.
	//End of line as delimeter
	var split_at = ", "; //your delimiter, cloud be anything e.g. "\n"
	var length_at = split_at.Length();

	//go through the string and split it
	var start = 0;
	while (true)
	{
		// check if start is out of bounds
		// find next match
		var pos = deliveryLocalString.Find(split_at, start);

		// no further occurence found?
		if (pos == -1)
		{
		
			// check if any characters remain at end of string
			if (deliveryLocalString.Length() > start)
			{
				var remainder = deliveryLocalString.Substring(start);
				deliveryStringTable.Add(remainder);
			}

			// abort loop
			break;
		}

		// otherwise add found string to newlineParsedTab
		var sub_length = pos - start;
		var substring = deliveryLocalString.Substring(start, sub_length);
		deliveryStringTable.Add(substring);

		// set new start position for next loop
		start = pos + length_at;
	}