Let's say I need to check a string, but that string could contain
French characters so I need to remove all French characters and
replace them with the their English counterpart.
Is there a way to do this?
long start_pos=1,len_look_for
len_look_for = len(look_for)
//find the first occurrence of look_for ...
start_pos = Pos(source,look_for,start_pos)
//only enter the loop if you find whats in look_for
DO WHILE start_pos > 0
//replace look_for with replace_with ...
source = Replace(source,start_pos,Len_look_for,replace_with)
//find the next occurrence of look_for
start_pos = Pos(source,look_for,start_pos+Len(replace_with))
LOOP
return source
--
Terry Dykstra (TeamSybase)
http://powerbuilder.codeXchange.sybase.com/
http://casexpress.sybase.com
product enhancement requests:
http://my.isug.com/cgi-bin/1/c/submit_enhancement
"Filetme" <phil_...@hotmail.com> wrote in message
news:2e7d60b2-b0eb-4e52...@x41g2000hsb.googlegroups.com...
I appreciate the response ...
I saw this code but I'm not sure it will work for me.
I need to do the equivalent of this Oracle command in PB.
translate(upper(ltrim(rtrim(COLUMN_VALUE))),
'1ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜ','1AAAAAACEEEEIIIIOOOOOUUUU')
So I don't really know any positions ... would I just look through the
string as well as the translate list checking for matches?
String accent = "ИЙКЛЫЩПОАВФийклыщпоавф"
String noaccent = "EEEEUUIIAAOeeeeuuiiaao"
String test = "Test : а й А Й"
String currentChar = ""
String result = ""
int i,j = 0
FOR i = 1 TO len(test)
currentChar = mid(test,i, 1)
j = pos(accent, currentChar)
IF j > 0 THEN
result += mid(noaccent,j,1)
ELSE
result += currentChar
END IF
NEXT
MessageBox(test, result)
Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
Ew. If you're going to process a single character at a time, at least
use a character array.
All those +='s are going to seriously slow down this loop for strings
of any significant length.
I agree. That's exactly how my Java version is designed.
http://www.rgagnon.com/javadetails/java-0456.html
For the array lookup, I was to lazy to do it in PB!
How do you do fast string concatenation in PB ?
But for _simple need_ like name and address processing in _interactive
application_, this solution is good enough.
Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
How do *I* do it? With a custom class I wrote to replace the built in
blob type.
Well, it still uses a blob internally, but I wrote a faster interface
for most operations. And a heap of useful shorthand methods for
things.
I've posted something like this before, but here's my fast string
building method;
public subroutine of_build_string (readonly string as_value, encoding
an_encoding);
long ll_ret
if isnull(as_value) then return
do
ll_ret = this.blobedit(il_length +1,as_value,an_encoding)
if not isnull(ll_ret) then exit
if len(ib_data)=0 then
ib_data=blob(space(128))
continue
end if
ib_data+=ib_data
loop while true
// drop the null terminator
if an_encoding = encodingansi! then
il_length=ll_ret -2
end subroutine
Bah, hit submit before I finished... that should have ended with;
// drop the null terminator
if an_encoding=encodingansi! then
il_length=ll_ret -1
else
il_length=ll_ret -2
end if
Ok, I got it.
I have posted a new HowTo on the subject.
http://www.rgagnon.com/pbdetails/pb-0264.html
Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets