Skip to Content

Splitting the String

Hi All,

 

I hope there no key word in SDK for splitting the string. Here i am sharing my attempt for splitting the string. If any improvement required in code or logic. If any of you have any alternate thought or any other technique which already exist in SDK. please let me know.

 

I hope SDK Experts Horst Schaude, Alessandro Iannacci, @Stefan Krauth …… has better coding or technique then this 🙂 .

 

Step 1: Reuse library for splitting the string. It has two importing parameters(STRING_QU_RE -> String to be split, SPLIT_QU_RE -> Splitting Variable, Return will be collection split strings ).

Reuse_library.PNG

 

Step 2: Logic for splitting the string.

Logic.png

Step 3: Business object for testing the Reuse Library for splitting the string.

Business Object.png

Step 4: Script for executing the Reuse Library.

Script.png

Step 5: Testing the Business Object for splitting the string.

 

5.a: Input the String and Split Key

output.PNG

5.b: Click on Split String.

output1.PNG

output2.PNG

If this blog is help full. Please Share it, Like it and Comment it below 🙂 😆 😆 .

 

Thanks,

Quddus.

14 Comments
You must be Logged on to comment or reply to a post.
  • /
      • Hi Ludger,

             Thanks.

             I debug it, when the function is running, the result is Ok.

            

        But at the end of the fuction run, it raise 4 errors at con.Find() and 4 errors at con.Substring(), every time is not success?

        • Hi Bin,

          for some reason, the script calls the substring method with a negative substring length: -16.

          So there is some bug or missing length/string validity check in the script causing this error.

          Please ask McQuddus to check and update the code.

          Best regards,

          Ludger

  • /
  • If anybody wants to copy & paste, this is my approach 🙂 .

    I did it a bit differently, because the original approach assumes that your split character is only 1 character long and that there is never a split character at the end of the string. (In the first case, that would leave you with the rest of your split character in the next line; in the second case, it would leave you with an extra line in the result.)

    My import variables are:

    IV_STRING : AP.Common.GDT::LANGUAGEINDEPENDENT_EXTENDED_Text;
    IV_SPLIT_AT : AP.Common.GDT::LANGUAGEINDEPENDENT_EXTENDED_Text;

    Also, the reuse function should be read-only so it can be used cross-deployment unit.

    import ABSL;
    import AP.Common.GDT;
    // takes the import string IV_STRING and returns a list of strings that was split
    // at the IV_SPLIT_AT character
    var result : collectionof DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
    
    // this converts IV_SPLIT_AT to "String" data type (otherwise there's an activation error)
    var split_at = IV_SPLIT_AT;
    
    var length_at = split_at.Length();
    
    // 1) if any of the strings are empty, return an empty result
    if (IV_STRING.Length() == 0 || length_at == 0)
    {
    	return result;
    }
    
    // 2) go through the string and split it
    var start = 0;
    while (true)
    {
    	// check if start is out of bounds
    	// find next match
    	var pos = IV_STRING.Find(split_at, start);
    
    	// no further occurence found?
    	if (pos == -1)
    	{
    		
    		// check if any characters remain at end of string
    		if (IV_STRING.Length() > start)
    		{
    			var remainder = IV_STRING.Substring(start);
    			result.Add(remainder);
    		}
    
    		// abort loop
    		break;
    	}
    
    	// otherwise add found string to result
    	var sub_length = pos - start;
    	var substring = IV_STRING.Substring(start, sub_length);
    	result.Add(substring);
    
    	// set new start position for next loop
    	start = pos + length_at;
    }
    
    // 4) return result
    return result;

    Kind regards
    Stefan

    /
    🙂