Question
Cognizant
IN
Last activity: 11 Aug 2020 14:30 EDT
How to extract the desired string from another string
I have a requirement like I have a string in the format 123400000000005678.my requirement is to seperate 1234 and 5678 and save it to 2 diff properties.how it can be done.one thing to note is middle 10 zeroes will be constant but length of string not both numerical values will be diff length only the middle zeroes is constant
-
Likes (1)
Mohammed Adil Saleem -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
FR
Hello,
Can you use OOTB functions like WhatComesBeforeFirst / WhatComesAfterLast
-
Gaurav Londhe
Cognizant
IN
Using this function I can give only one charactor at a time.it won't take string
Pegasystems Inc.
GB
What about using pxReplaceAllViaRegex(String,String,String)?
You are looking to replace certain parts of the string with "" in both cases.
Cognizant
IN
I can use it and replace 0 with blank or space but then the problem is splitting the numbers
Coforge DPA
GB
Hi Praveen
As Marc mentioned the two functions will work.
whatComesbeforefirst zero will give : 1234
whatcomesafterlast zero will give: 5678
You can store these in properties.
The only constraint here is that there should not any other zero in the numbers. For example 100400000000005608, if the number is this way then the logic will fail.
Regards
Bhavya
Cognizant
IN
Hi bhavya,
Ya that is the constraint I am facing with the whatcomesbefore and after functions.
If there is a way to pass string instead of char then it's useful
Coforge DPA
GB
Hi
I tried the below logic and it seems to work for both your scenarios.
Result:
Hope this helps.
Regards
Bhavya
-
Praveen P Rajendra Prasad Ega Nithyananthan K Swathi Madireddi
Blue Rose Technologies
DE
Hi,
You can try as below expressions,
@String.whatComesBeforeFirst(@String.replaceAll("123400000000005678","0000000000","*"),'*')
@String.whatComesAfterFirst(@String.replaceAll("123400000000005678","0000000000","*"),'*')
Please see screenshot below,
-
Praveen P Rajendra Prasad Ega Kavi Priya