Skip to Content
Author's profile photo Md Quddus

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.

Assigned tags

      14 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Great document.....

      Thanks for sharing this information..........

      Regards,

      Mithun

      Author's profile photo Md Quddus
      Md Quddus
      Blog Post Author

      Thanks Mithun Suthar

      Regards,

      Quddus.

      Author's profile photo Former Member
      Former Member

      Thanks for sharing your work..

      Regards,

      K. K. Nikhil.

      Author's profile photo Chandan Bankar
      Chandan Bankar

      Great!! Thanks for sharing .... 🙂

      Author's profile photo MOHD SIRAJUDDIN
      MOHD SIRAJUDDIN

      Great work Quddus.

      Regards,

      Siraj.

      Author's profile photo Former Member
      Former Member

      Nice work Quddus ,

      Thanks and regards ,

      Lokesh Sai .

      Author's profile photo Puneet Mittal
      Puneet Mittal

      Very Much Thanks for sharing !!!

      It is really helpful . 

      Author's profile photo Former Member
      Former Member

      good work Quddus,

      Regards,

      Sreelatha.

      Author's profile photo Bin Huang
      Bin Huang

      Hi Quddus,

           When I test in my test system, click on Split String, it raise:

          

           Thanks.

      Author's profile photo Ludger Buenger
      Ludger Buenger

      Hi Bin,

      this is very likely due some of the strings being empty/initial.

      Author's profile photo Bin Huang
      Bin Huang

      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?

      Author's profile photo Ludger Buenger
      Ludger Buenger

      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

      Author's profile photo Former Member
      Former Member

      Greetings, colleagues.

      Fixed a bug in the code

      Author's profile photo Stefan Barsuhn
      Stefan Barsuhn

      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