Normal Topic problems with Split functioni (Read 876 times)
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
problems with Split functioni
Feb 26th, 2004 at 5:56pm
Print Post Print Post  
I have been able to use Split before, w/ no problems. 
However, this time I am not so lucky.

I am trying to detect " " (spaces) in a string, splitting up the string into various words.  I can detect the position of the space using @In, I retrieve the correct value of the modified original string after the split, but the value from split (ie., the original string upto the first occurence of the space) is always 0.

For example: if I have vStr="mad cat sam" and vtemp=Split(vStr, " ")

these are the results:
@In(vStr," ") = 4
vtemp=0
vStr="cat sam"


any clues? TIA
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: problems with Split functioni
Reply #1 - Feb 26th, 2004 at 6:19pm
Print Post Print Post  
Is vTemp declared as String?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: problems with Split function
Reply #2 - Feb 26th, 2004 at 6:21pm
Print Post Print Post  
yes it is.  (sorry i wasn't more specific)
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: problems with Split functioni
Reply #3 - Feb 26th, 2004 at 6:29pm
Print Post Print Post  
Could you show us the actual code? It will be easier to spot/test the problem if I can see exactly what you're doing.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: problems with Split functioni
Reply #4 - Feb 26th, 2004 at 8:37pm
Print Post Print Post  
I have a function in Global Code and I am calling it from a form. The code is as follows:

function format_string(str1 as string) as string

var vstr, fstr as String

fstr=""
vstr=""


while @Len(str1) > 0 and @In(str1," ") > 0
{      
     vstr=Split(temp," ")
     fstr=fstr+ " " + toupper(@Left(vstr,1)) +  tolower(@Right(vstr, @Len(vstr)-1))
      
   
} // end while
fstr=fstr+ " " + toupper(@Left(vstr,1)) + tolower(@Right(vstr, @Len(vstr)-1))
writeln("returning fstr as " + fstr)

return fstr
end function
  
Back to top
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: problems with Split functioni
Reply #5 - Feb 26th, 2004 at 8:40pm
Print Post Print Post  
I'm calling it from a text LE named LastName as:

LastName=format_string(LastName)

I'm trying to format strings with multiple words such that the first letter of each word is capitalized and the rest is lowercased.

  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: problems with Split functioni
Reply #6 - Feb 26th, 2004 at 9:11pm
Print Post Print Post  
When you declare multiple variables on the same line, you still have to specify a type for each.

Your line:
var vstr, fstr as String

... is resulting in vstr defaulting to type Int. Make it:
var vstr as String, fstr as String

Also, it looks like your code may result in an endless loop. You are splitting temp (which is undeclared), but you are checking str1 to see if you should continue running.

I also recommend that you return the result of your function to a variable, instead of setting the element value directly. This will give you a chance to make sure that the function succeeded before whacking the original value.

If you're interested, there is an example of making Initial Caps posted in the Programming Examples
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: problems with Split functioni
Reply #7 - Feb 26th, 2004 at 9:51pm
Print Post Print Post  
thanx, that did the trick

as for the endless loop, I was playing around w/ variable names, "temp" should have been "str1" =)
  
Back to top
IP Logged