cancel
Showing results for 
Search instead for 
Did you mean: 

to find out the POSITION OF Nth OCCURANCE OF A PARTICULAR CHARACTER

Former Member
0 Kudos

Hi,

Is it possible to find out the POSITION OF Nth OCCURANCE OF A PARTICULAR CHARACTER IN A STRING in crystal reports?

Eg:

I have a string abcdabcdabcd

Now I want to know the position of the 2nd occurance of u2018au2019 in the string u2018abcdabcdabcdu2019

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

You must do it in sql query with using charindex, something like

declare @string varchar(100)

declare @searched varchar(1)

select @searched = 'a'

select @string = 'abcdabcdabcd'

select charindex(@searched, @string, charindex(@searched, @string, 1) +1)

Former Member
0 Kudos

hi,

dim MainStr as String=u2018abcdabcdabcdu2019

dim SubStr as String='a' 'Give which alphabet do you want.

dim Num as integer=2 'Give which 'a' do you want. i gave for second a.

dim ResultStr as string

dim ResultNum as integer=1

dim Position as integer=0

for i as integer=0 to MainStr.length-1

ResultStr=MainStr.SubString(i,1)

if ResultStr=SubStr then

ResultNum+=1

if ResultNum=Num then

position=i+1

exitfor

endif

endif

next

hope this solves your problem

regards,

varma

Former Member
0 Kudos

Hi,

Thanks for your inputs.

But I need the solution in Crystal Reports XI

Former Member
0 Kudos

You can embed SQL to your report. The best one to use might be PATINDEX, so that checking the occurence will be easier for you.

Thanks,

Gordon

Former Member
0 Kudos

Hi,

I want to achieve the following sql code in crystal reports XI syntax:

instr(OTNAME,'.',1,4)

(This implies that: the 4th occurance of '.' is to be searched from OTNAME starting from position 1)

The value of OTNAME is like this: '73.2.700.710.U.BASE.F.I.5.6.5.2134.1.2'

Please help me find a way to achieve the above in crystal reports XI