Viggen
(Starting to like KiXtart)
2002-09-24 04:46 PM
Two "small" problems

Hi All!

It's been a while since I wrote a question here, but now I'm stuck.
Hopefully someone can answer this.

If I have a string that looks like this:
"abclefgh"
How do I replace the "l" with a "d" ?

The problem is that the lenght of the string is not constant and it's not always "l" that has to be replaced.

Problem 2:
If I have for example a name that looks like this:
"John-patrick"
How do I change that to "John-Patrick" ?

T.I.A


Jack Lothian
(MM club member)
2002-09-24 04:52 PM
Re: Two "small" problems

Maybe this UDF might help. If not it will give you some ideas.

String replacement function


Howard Bullock
(KiX Supporter)
2002-09-24 05:02 PM
Re: Two "small" problems

In 4.10 or higher:

$a = join(split("abclefgh","l"),"")


Howard Bullock
(KiX Supporter)
2002-09-24 05:04 PM
Re: Two "small" problems

For the case issue, you can use SetOption( )

to turn on case sensitivity and possibly do something like above with "-p" and "-P".

[ 24. September 2002, 17:04: Message edited by: Howard Bullock ]


Les
(KiX Master)
2002-09-24 05:11 PM
Re: Two "small" problems

For case sensitivity, could always do the == thing.
code:
Break on

get $_
Select
Case $_ == "X"
? "You hit uppercase X"

Case $_ == "x"
? "You hit lowercase x"

Case 1
? "You hit something else"

EndSelect

get $_



Viggen
(Starting to like KiXtart)
2002-09-25 05:22 PM
Re: Two "small" problems

Thanks!!

The "a = join(split("abclefgh","l"),"")"-thing got me halfway...

But I'm still stuck on "problem 2"
Let me try and clarify it a bit.

I'm readin an input-file, make som changes and saves in an output-file like this:

Input:                            Output:
SMITH JOHN                    John Smith;john.smith
OLSEN JOHN-PATRICK        John-patrick Olsen;john-patrick.olsen
ANDERSON ANNA-GRETA    Anna-greta Anderson;anna-greta.anderson

I need an "easy" way to change the first letter after the "-" to uppercase
I tried with Join & Split, but my code just grew to something like 4 pages, so there must be an easier way (I hope...)


LonkeroAdministrator
(KiX Master Guru)
2002-09-25 05:40 PM
Re: Two "small" problems

well, for making the first char upper and others low with split and join:
code:
$fullname=split($fullname)
for $counter=0 to ubound $fullname
$fullname[$counter] = ucase(left($fullname[$counter],1))+lcase(substr($fullname[$counter],2)
next
$fullname=join($fullname)

then, for the "-" do the same:
code:
$fullname=split($fullname,"-")
for $counter=0 to ubound $fullname
$fullname[$counter] = ucase(left($fullname[$counter],1))+lcase(substr($fullname[$counter],2)
next
$fullname=join($fullname,"-")

cheers.
 


Howard Bullock
(KiX Supporter)
2002-09-25 05:52 PM
Re: Two "small" problems

Try this:
code:
$a="OLSEN JOHN-PATRICK"
? $a
$FullNameArray = split($a)
for $y=0 to ubound($FullNameArray)
if Instr($FullNameArray[$y],"-")=0
$FullNameArray[$y]=ucase(left($FullNameArray[$y],1)) + lcase(substr($FullNameArray[$y],2))
else
$NameArray = split($FullNameArray[$y],"-")
for $x=0 to ubound($NameArray)
$NameArray[$x]=ucase(left($NameArray[$x],1)) + lcase(substr($NameArray[$x],2))
next
$FullNameArray[$y] = join($NameArray,"-")
endif
next
$a = join($FullNameArray," ")
? $a

{edit} Beat out again by the one that never sleeps. [Frown]

[ 25. September 2002, 17:54: Message edited by: Howard Bullock ]


Jack Lothian
(MM club member)
2002-09-25 05:56 PM
Re: Two "small" problems

Proper names are not nice. You need to deal with stuff like O'Neil, MacDonald, and double names with & without hyphens, plus more. Once you start down the path of displaying the users names correctly, it may lead farther then you think.

Viggen
(Starting to like KiXtart)
2002-09-26 11:24 AM
Re: Two "small" problems

YES!!!
It works!!

Thanks guys!

Jack:
I know, but I got a note the other day that said "Fix This NOW!" from my boss, so now the next step is to make him understand that this can't be done on every combination of names. [Roll Eyes]

Thanks again!

// Viggen