Questions...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hy,

I was wondering if there is a procedure/function
that converts EG : "12345" to 12345
I created this :

[BEGIN]

function kwadraat(integer dinges,integer totde,integer extra)
integer temp1
temp1=dinges
if totde=1 then
elsif totde=0 then temp1=1 else
if extra=1 then
 for a=2 to totde do
  temp1=temp1*dinges
 end for
else
 for a=2 to totde-1 do
  temp1=temp1*dinges
 end for
end if
end if
return temp1
end function

global function seq2int9(sequence string)  -- ONLY 1-9 DIGIT SEQUENCES
!!!!
integer number,tnmb
if length(string)=1 then
 number=string[1]-48
else
 number=kwadraat(10,length(string),0)
 number=number*(string[1]-48)
 for a=1 to length(string)-1 do
  tnmb=kwadraat(10,length(string)-a-1,1)
  number=number+(tnmb*(string[a+1]-48))
 end for
end if
return number
end function

[END]

EG.
test=seq2int9("12345")
RESULT:
test=12345

-------------------------------------------------------------------

And also, if there's a proc/func that is like match(),
but gives ALL the locations back.
I wrote this :

[BEGIN]

function add_place(sequence str)
sequence tmp
tmp=""
if length(str)=0 then
 str=repeat(" ",1)
else
 tmp=str
 str=""
 str=repeat(" ",length(tmp)+1)
 for a=1 to length(tmp) do
  str[a]=tmp[a]
 end for
end if
return str
end function

function remove_place(sequence str,integer place)
if length(str)=1 then
 str=""
else
 if place=length(str) then
  str=str[1..length(str)-1]
 elsif place=1 then
  str=str[2..length(str)]
 else
  str=str[1..place-1]&str[place+1..length(str)]
 end if
end if
return str
end function

global function multimatch(sequence str,sequence cstr)
sequence temp1,temp2
object loc,pl
temp1=""
temp2=cstr
pl=0
while 1 do
 loc=match(str,temp2)
 if loc=0 then exit else
  pl=pl+1
  temp1=add_place(temp1)
  temp1[pl]=loc+((pl-1)*length(str))
  for a=1 to length(str) do
   temp2=remove_place(temp2,loc)
  end for
 end if
end while
return temp1
end function

[END]

EG.
test=multimatch(" ","Hy, how are you doing ?")
RESULT:
test={4,8,12,16,22}


Bye,
PQ
QC


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu