1.find most occurrences of a character.
for exm: input:aaabbbbdddddyyy
output: d 5 times
how can i get that?
Answers were Sorted based on User's Feedback
Answer / manish dwivedi
By using SCAN OP- Code we can find out the most occurrences
of a character.
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / kamlesh
you need to write dow loop ,initialize counter variable=0
and use scan opcode
when first occur of 'd' finds scan returns its position
in string , increment counter=counter+1 then you have to
use substr(yrstring:pos+1:'d')now again same process
is done and if 'd' char found increment counter by 1
this process is continue until complete yrstring is scaned.
finally total number of 'd' is accumulate in COUNTER
variable.
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / bharatiya
I was trying it last night and wrote the below code that works for this scenario, please have a look----
DArr1 S 1 DIM(10)
DArr2 S 1 DIM(10)
DCnt S 2 0
Dn1 S 2 0 Inz(1)
Dn2 S 2 0 Inz(1)
DFld1 S 15 Inz('aaabbbbdddddyyy')
C
C Do 15
C EVAL Arr1(n1) = %subst(FLD1:n1:1)
C If Arr1(n1) = 'd'
C Eval Arr2(n2) = Arr1(n1)
C Eval n2 = n2 +1
C Endif
C Eval n1 = n1+1
C Enddo
C Eval cnt = n2 - 1
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / kar
Use Scan Opcode, and give the result field as array name
instead of a ordinary field.
After the execution of statement, display array values, and
you can find the all occurrences.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / ssss
fld1 = aaabbbbdddddyyy
res = %check('d':fld1:8) ;
If res > 0;
Cnt = res-8;
Endif;
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / vipul dixit
With the help of %Scan built in function or Scan op-code we
can do this.
we should define a data structure and write like this way:-
DDs s
C Eval Ds = %Scan('d':Source:1).
It will fetch the position of the scanned character,and
after that we will count all the positions as DS elements.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sagar wagh
Dcl-S inputString Char(30) Inz('aaabbbbdddddyyy');
Dcl-S charCount Int(10);
Dcl-S maxCount Int(10) Inz(0);
Dcl-S maxChar Char(1);
Dcl-S i Int(10);
Dcl-S j Int(10);
For i = 1 to %Len(%TrimR(inputString));
charCount = 0;
For j = 1 to %Len(%TrimR(inputString));
If %Subst(inputString: j: 1) = %Subst(inputString: i: 1);
charCount += 1;
EndIf;
EndFor;
If charCount > maxCount;
maxCount = charCount;
maxChar = %Subst(inputString: i: 1);
EndIf;
EndFor;
Dsply ('Character ' + maxChar + ' occurs ' + %Char(maxCount) + ' times');
*InLR = *On;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manoj
As per my understanding using Scan opcode we can't find out
most occurrences of a character.
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / deepak
D:a 15a inz('aaabbbbdddddyyy')
D:b 1a
D:c 15a
D:i 2p 0
D:e 2p 0 inz(1)
C: Eval b=%sst(a:e:1)
C: eval c *cat b
C: If b='d'
C: eval replace(d:x)
C: eval i=i+1
C: eval e=e+1
C: i dsply
C: seton lr
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / prasanna
You can find it with opcode scan and in the result field we
should have an array
Is This Answer Correct ? | 0 Yes | 2 No |
write an RPG program to calculate the marks of 5 students (A,B, C, D, E)in 3 different subjects (eng, math, sci) an display on the screen
Suppose I have 3 jobs a b and c. I want to submit b after successful completion of a and want to submit c after successful completion of b. Without using job scheduler or job queue, how can I do that through cl program?
what is kids-rpg?
Why Rpg/400 is Famous?
what do you mean by SESSION/DEVOCE ERROR?
steps involved in debugging and types of debugging modes?
How to print Superscript / Subscript from RPG400
1.Suppose my file has 10 fields and I want to make the 2nd field Zeros in all records. And assume I have millions of records and I dont want to read each record and update the desired field with 0. Any other way to do this in one step operation? 2. Assume my file has 100 records and I want to see only first 10 records. Is this possible through LF? 3.I have 3 jobs A B and C. I want to submit B after successful completion of A and want to submit C after successful completion of B. Without using job scheduler or job queue, how can i do that through CL program? 4.What is difference between Bind by copy and bind by reference?
what are the types of identifers
How do you find out whether a record is present in the physical file without reading the file? for Example Employee No: 100 in an Employee master.How do we find out whther 100 is present in Employee master without reading the file?
11 Answers Bank Of America, CSC, IBM,
How to call one program from another program in RPG? please help me with the code
how do u find whether a record is locked or not??/