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 |
1)how to do date validation in rpg? 2)how to delete dUPLICATE RECORDS?
1.How can you search an entire source file for a particular field name? 2.How can you find the differences between two versions of the source for the same program? 3.What is a hidden field as it relates to a sub file? 4.How do you display a sub file that has no records in the sub file?
Program to read marks of 10 students for 4 subjects and compute and display total marks and status of each student in rpg
How to declare the pull button in AS/400..
How to read a record from file where there is multiple record occurrence is available?
I have a PF(ABC)with no key fields. PF(ABC)have 2 fields (cusno and cusname). Please let me know how can i read the cusno = 1150 directly from PF in CL and RPG program(Without creating the LF and without reading the complete file and then compare 1150)
Hello, I want to extend a length of field in my Display file(Subfile). Please suggest the possible steps. Thanks
How can we make use of SETLL operation in CL?
if there is a module object , how to find the program object for this module object.Assume the module object name and program object name is not same.
How do you do indexing in a physical file?
how do I play {insert rpg system here}?
Interviewer asked me write down DDS for load all subfile .can anybody write dds