Page 1 of 1 1
Topic Options
#70229 - 2002-09-24 04:46 PM Two "small" problems
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
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

Top
#70230 - 2002-09-24 04:52 PM Re: Two "small" problems
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Maybe this UDF might help. If not it will give you some ideas.

String replacement function
_________________________
Jack

Top
#70231 - 2002-09-24 05:02 PM Re: Two "small" problems
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
In 4.10 or higher:

$a = join(split("abclefgh","l"),"")
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70232 - 2002-09-24 05:04 PM Re: Two "small" problems
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70233 - 2002-09-24 05:11 PM Re: Two "small" problems
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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 $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#70234 - 2002-09-25 05:22 PM Re: Two "small" problems
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
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...)

Top
#70235 - 2002-09-25 05:40 PM Re: Two "small" problems
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
 
_________________________
!

download KiXnet

Top
#70236 - 2002-09-25 05:52 PM Re: Two "small" problems
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70237 - 2002-09-25 05:56 PM Re: Two "small" problems
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
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.
_________________________
Jack

Top
#70238 - 2002-09-26 11:24 AM Re: Two "small" problems
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
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

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.06 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org