ER problem: find string in string

hharald

Member
Hello List,

writing some ER for a report i have the following problem:
I need to find a string in another string.

Example:

i need to find 'cpg' in 'bkhbhjabdsf cpg jasbdhasd'

i even don't need the position, only if the string is included...

Looking in the KG i found nothing, BSFN B96701 is not working as expected.
Has anyone a idea how to do it?
Any help would be appreciated!

Thank you,
hharald
 

sdwjdelist

Member
hharald,

B96701 is a LOCAL execution only BSFN...are you running it on the server? Reference the following SARs for more information: 5418119, 5296550, and 4944525.

For server use, you'd need to write your own BSFN...probably not preferred.

ER manipulation could work by truncating your original string one position to the left (within a loop), and retest for the desired value in positions 1 + n. If your string search argument is variable in length, you could use multiple custom sections based on a pre-determined argument test in the mainline, which would call the appropriate custom section.

Hope this helps...good luck.

Regards, SDW
 

jastips

Active Member
I created a BSFN for finding string position in string. (I could not find any thing in JDE)
I am attaching .C, .H and data structure document. With the help of attached docs you should be able to create a "C" BSFN your self.

I hope this might help !!!!!!!!
 

Attachments

  • 53155-FindStr.zip
    78.9 KB · Views: 132

jdeproffesional

Active Member
This can be accomplished by NER, no need for C++.
1-Get length of string.
loop to end of substring.
begin
substring one charater at a time
if first charcter found raise flag yes or count 1
substring next charcter , if second char found flag yes or count 2
..... etc to third.
if seond not found, restart counters or flags.
end loop

Good luck.
 

hharald

Member
Re: ER problem: find string in string (Here is the NER Solution)

By the way (i have found my own message while i was searching for somethin else....)

Here is the solution i programmed back then (it's not optimized and for sure i have not build something very impressive or new, but it works):



This example searches for the upper-case 'CPG' in a given String and sets a flag if it is found (i had to use two flags, with only one it was not working....):


// ##############################################################
//
// START: Check if 'CPG' is included in the RV ChemicalName
//
//
// ##############################################################
// Make sure everything is in a defined state!
//
VA rpt_testFLAG1_DMFL = "0"
VA rpt_testFLAG2_DMFL = "0"
VA evt_Counter_MATH01 = 0
VA evt_ChemicalNameCopy_AASC = upper([RV ChemicalName])
VA evt_ChemicalNameLenght_Math01 = length([VA evt_ChemicalNameCopy_AASC])-2
//
//
While VA rpt_testFLAG2_DMFL is not equal to "1"
//
//
VA evt_testSTRING1_A301 = substr([VA evt_ChemicalNameCopy_AASC],[VA evt_Counter_MATH01],3)
//
If VA evt_testSTRING1_A301 is equal to "CPG"
VA rpt_testFLAG1_DMFL = "1"
VA rpt_testFLAG2_DMFL = "1"
End If
//
If VA evt_Counter_MATH01 is greater than VA evt_ChemicalNameLenght_Math01
VA rpt_testFLAG2_DMFL = "1"
End If
//
VA evt_Counter_MATH01 = [VA evt_Counter_MATH01]+1
//
End While
//
If VA rpt_testFLAG1_DMFL is equal to "1"
*********************i.E.: DO SOMETHING
Else
*********************i.E.: GO HOME
End If

Cheers, happy X-Mas and wonderful New-Years partys to you all,
HHarald
 
This solution is not correct ...
If the words will be in the diferents positions in the string the logic tell to us wich the strinf are find

Ex.:
I´m looking for string "CFG" in the string "XXXC XXF XXXG"
For your logic the string "CFG" will be in the string "XXXC XXF XXXG" but only the same words in the diferent positions was be presents.
 

Pranoy

Member
I created a BSFN for finding string position in string. (I could not find any thing in JDE)
I am attaching .C, .H and data structure document. With the help of attached docs you should be able to create a "C" BSFN your self.

I hope this might help !!!!!!!!
jastips,

thanks so much for sharing this, it really helped me today.
I have further modified this to use MOTEXT of 30000 character length for my requirement by replacing the existing QUPATH in Datastructure and also replacing strstr api unicode api jdeStrstr api.

- Pranoy
 

Kim Schmidt

Well Known Member
Pranoy, there are several business functions that run on both client and server that can do this. One good example is B952334 "Find a String in a String", which can search a string up to 32000 characters in size. I hope you didn't bother to write your own function - that would be a risk of relying on old solutions found in an 18 year old thread!
 

Pranoy

Member
Pranoy, there are several business functions that run on both client and server that can do this. One good example is B952334 "Find a String in a String", which can search a string up to 32000 characters in size. I hope you didn't bother to write your own function - that would be a risk of relying on old solutions found in an 18 year old thread!

Hi Kim,

I dont think it gives out the position of string, correct me if I'm wrong. Is there any std BSFN which gives out the position? I didnt find yet? but the code shared above works.

1635258644534.png

Currently I'm using B7900007 to replace the string with string.

1635258460286.png

Thanks,
Pranoy
 
Last edited:

johnd

Active Member
Hi Pranoy

What exactly are you trying to do? Parse, replace, substring the text? There are lots out there (all on F9862 and ObjectBrowser to test to check) to do various things in isolation or alone.

Example: If the text is separated at all, you can use Parse String B98220D to split it up. In you case it looks like ' '

Do Section =-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Split out OBNM VERS etc
// Get OBJ VERS and extension from F986110.FUNDFU2
// FNDFUF2 is stored as a string made up of "OBJ_VERS_JOBNBR_PDF"
// =-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] = rtrim([BC Foundation - Future Use 2 (F986110.0) [FNDFUF2]], <Blank>)

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_NameObjectOBNM [OBNM] <- szOutputObjectSegment [OMWOBJID]
"0" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_VersionVERS [VERS] <- szOutputObjectSegment [OMWOBJID]
"1.00" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_DocumentExtensionDCEX [DCEX] <- szOutputObjectSegment [OMWOBJID]
"3.00" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]


If you just want to know it's in the text at all, B952334 is perfect. Same if you just want to replace.

If you need to know the starting position of the text you are looking for, first check it's there using one of the above, then chop one off the start of the text and loop substringing out the length you're looking for
When you hit a match, there's your position

Looking for Egg in fishEggfish would be
Yes I found Egg
Now check fis = Egg (starting pos 0)
No so try ish = Egg (starting pos 1)
No so try shE = Egg (starting pos 2)
No so try hEg = Egg (starting pos 3)
No so try Egg = Egg Boom! There's your answer (starting pos 4)
 
Last edited:
Top