Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

Answer / ssss

fld1 = aaabbbbdddddyyy
res = %check('d':fld1:8) ;
If res > 0;
Cnt = res-8;
Endif;

Is This Answer Correct ?    1 Yes 1 No

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

Post New Answer

More RPG400 Interview Questions

How to index LF by relative record no (RRN)

1 Answers  


Hi friends, Can you give the solution for the below mention simple code.and explain.what is output D CHR1 S 4A INZ('PEN') D CHR2 S 10A INZ('MYGET') D CHR3 S 8A INZ('GOOD') D CHR4 S 22A INZ C MOVEL CHR1 CHR4 C MOVE CHR2 CHR4 C EVAL CHR4=CHR3 C MOVE CHR1 CHR4

4 Answers  


What would be the effect on the field where reverse image, underline and high intensity?

7 Answers   IBM,


Can someone tell me tell me what is meant by message wait...?

1 Answers  


difference betwen keywords and opcodes

3 Answers  


How to get only unique records from a file which contains duplicate data using CPYF command ? Example : FILEA has duplicate records and FILEB is a UNIQUE defined.... and I want to get the data from FILEA to FILEB by eliminating all the duplicate records...

2 Answers  


How to update physical file in rpgle without using display file?

4 Answers   GalaxE, IBM, TCS,


What is the diff bw PF/LF Name and their Record format name? what is restriction in record format then file name?

0 Answers   Wipro,


What is the name of default out queue when user logs inn to syatem with valid profile?

3 Answers   IBM,


what is flat file?

1 Answers   IBM,


What is difference between bind by copy and bind by reference?

0 Answers  


What is journalling and commitment control?

3 Answers   IBM,


Categories