HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Find letter function

07-03-2006, 01:37 PM#1
The)TideHunter(
Ok, i decided to make a function that returns the position of a letter in a string.
Here it is:

Collapse JASS:
function CF_FindLetter takes string whichCharacter, integer letterCount, string source returns integer
    local integer i = 1
    local integer newCount = letterCount
    if(StringLength(whichCharacter) == 1) then
        loop                                                      
            exitwhen i == StringLength(source)            
            if(SubString(source, i-1, i) == whichCharacter) then      
                if(letterCount == 0) then                 
                     return i                                       
                endif                                               
                set letterCount = letterCount - 1                   
            endif                                                   
            set i = i + 1                                           
        endloop                                                  
    endif                                                           
    return 0                                             
endfunction
The problem is its not working. It does nothing.
Any help?
Edited because: Changed to Griff's post.
07-03-2006, 01:41 PM#2
Captain Griffen
Replace:

Collapse JASS:
            if(SubString(source, i, i) == whichCharacter) then

With:

Collapse JASS:
            if(SubString(source, i-1, i) == whichCharacter) then

Oh, and define i as 1 to begin with.
07-03-2006, 02:00 PM#3
The)TideHunter(
Hmm, ok.
Using (1, 1) has worked in the past for the first letter though, i think that was because it was GUi and the SubStringBJ uses -1. Which i just realised lol.
Thanks for poiting that out.