Does anyone have a MACRO to convert and return a string in Uppercase or Lowercase? I've searched!
Posted on 2004-05-20 02:46:34 by SubEvil
Since I don't think there is an example, and I can't wait ... here's my inital (currently working) attempt:




UCASE MACRO String :REQ
LOCAL NewString
NewString EQU <>
FORC Char, <String>
IFIDNI <Char>, <a>
NewString CATSTR NewString, <A>
ELSEIFIDNI <Char>, <b>
NewString CATSTR NewString, <B>
ELSEIFIDNI <Char>, <c>
NewString CATSTR NewString, <C>
ELSEIFIDNI <Char>, <d>
NewString CATSTR NewString, <D>
ELSEIFIDNI <Char>, <e>
NewString CATSTR NewString, <E>
ELSEIFIDNI <Char>, <f>
NewString CATSTR NewString, <F>
ELSEIFIDNI <Char>, <g>
NewString CATSTR NewString, <G>
ELSEIFIDNI <Char>, <h>
NewString CATSTR NewString, <H>
ELSEIFIDNI <Char>, <i>
NewString CATSTR NewString, <I>
ELSEIFIDNI <Char>, <j>
NewString CATSTR NewString, <J>
ELSEIFIDNI <Char>, <k>
NewString CATSTR NewString, <K>
ELSEIFIDNI <Char>, <l>
NewString CATSTR NewString, <L>
ELSEIFIDNI <Char>, <m>
NewString CATSTR NewString, <M>
ELSEIFIDNI <Char>, <n>
NewString CATSTR NewString, <N>
ELSEIFIDNI <Char>, <o>
NewString CATSTR NewString, <O>
ELSEIFIDNI <Char>, <p>
NewString CATSTR NewString, <P>
ELSEIFIDNI <Char>, <q>
NewString CATSTR NewString, <Q>
ELSEIFIDNI <Char>, <r>
NewString CATSTR NewString, <R>
ELSEIFIDNI <Char>, <s>
NewString CATSTR NewString, <S>
ELSEIFIDNI <Char>, <t>
NewString CATSTR NewString, <T>
ELSEIFIDNI <Char>, <u>
NewString CATSTR NewString, <U>
ELSEIFIDNI <Char>, <v>
NewString CATSTR NewString, <V>
ELSEIFIDNI <Char>, <w>
NewString CATSTR NewString, <W>
ELSEIFIDNI <Char>, <x>
NewString CATSTR NewString, <X>
ELSEIFIDNI <Char>, <y>
NewString CATSTR NewString, <Y>
ELSEIFIDNI <Char>, <z>
NewString CATSTR NewString, <Z>
ELSE
NewString CATSTR NewString, <Char>
ENDIF
ENDM
EXITM <NewString>
ENDM
Posted on 2004-05-20 06:04:03 by SubEvil
Can't you write it more simply, by doing a range-check on the chars ('a'-'z') and then offsetting those to become uppercase ('A'-'Z'). Should be much more compact and faster.

Something like:


IF i GE 'a'
IF i LE 'z'
newstring CATSTR <i-32>
ENDIF
ELSE
newstring CATSTR <i>
ENDIF


Haven't tested it though, modified a macro of mine that made a text all uppercase and offsetted it, so it could be used in a lookuptable.
Posted on 2004-05-20 06:18:33 by Scali
Can you post a copy of your MACRO?

I'm having big problems with this 'type' of MACRO!

I understand the theory. But having implementation problems!

For one thing, in the "newstring CATSTR <i-32>" line (Sould be newstring CATSTR newstring, <i-32>), the result for hello is

h - 32e - 32l - 32l - 32o - 32

As you can see, there is no 'ASCII value' substitution for i.
Posted on 2004-05-20 07:33:43 by SubEvil
My macro was different, it used db i-32 or db i-64 to dump each byte directly into the sourcecode.
Perhaps it should be <i>-32... Or something else. Not sure.
Perhaps it's not possible at all. But I would find that rather disappointing then.
Posted on 2004-05-20 07:44:34 by Scali
I've tried <i> - 32 already :( Gives me a:
error A2051: text item required

message. :( Any other suggestions
:stupid:
Posted on 2004-05-20 08:10:29 by SubEvil
<i>-('a'-'A') perhaps?
No idea :)
Posted on 2004-05-20 08:15:58 by Scali
Tried that :(
Also:
  FORC Char, <String>

IF <Char> GE 'a'
Echo Char
ENDIF
ENDM

Generates errors :(
error A2009: syntax error in expression

Tried:
  FORC Char, <String>

IF Char GE 'a'
Echo Char
ENDIF
ENDM

Gives:
error A2006: undefined symbol : h
Posted on 2004-05-20 08:36:16 by SubEvil
Well, my entire macro was:



SCROLLTEXT MACRO string
LOCAL i

; Convert ASCII to font indices
FORC char, <string>
i CATSTR <'>, <char>, <'>

IF i GE 'a'
IF i LE 'z'
db i-64
ENDIF
ELSE
db i-32
ENDIF
ENDM
ENDM


Perhaps it may be of some use... but I dunno.
It's been too long since I've done macros. I'd have to study the manual.
Posted on 2004-05-20 08:42:20 by Scali
One way to do it would be using a lookup table. Use INSTR to find out if the character is a lowercase letter - if so the result will be an index into that string. Use the index with SUBSTR to place a uppercase character into the string.
Posted on 2004-05-20 10:15:56 by bitRAKE
I use these macros



; ????????????????????????????????????????
; Macro: @Lower
; Purpose: Converts a symbol string to lowercase.
; Arguments: Symbol string.

@Lower macro String:req
local LowerStr, Letter, Pos, Character

LowerStr textequ <>
% forc Letter, <String>
Pos InStr <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, <Letter>
if Pos gt 0
Character SubStr <abcdefghijklmnopqrstuvwxyz>, Pos, 1
else
Character textequ <Letter>
endif
LowerStr CatStr LowerStr, Character
endm
exitm LowerStr
endm

; ????????????????????????????????????????
; Macro: @Upper
; Purpose: Converts a symbol string to uppercase.
; Arguments: Symbol string.

@Upper macro String:req
local UpperStr, Letter, Pos, Character

UpperStr textequ <>
% forc Letter, <String>
Pos InStr <abcdefghijklmnopqrstuvwxyz>, <Letter>
if Pos gt 0
Character SubStr <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, Pos, 1
else
Character textequ <Letter>
endif
UpperStr CatStr LowerStr, Character
endm
exitm UpperStr
endm



Regards,

Biterider
Posted on 2004-05-20 11:02:41 by Biterider
Biterider, I forgot about those :)

I just finished drafting up the same macros from scratch, but you beat me to the punch <LoL>
;########################Test.asm###########################

.486
.model flat, STDCALL
option casemap :none ; case sensitive

include \Masm32\include\windows.inc
include \Masm32\include\kernel32.inc
include \Masm32\include\user32.inc
include \Masm32\include\Masm32.inc
includelib \Masm32\lib\Masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


UPPER MACRO szTxt:REQ
LOCAL val1, sz1, sz2
sz2 TEXTEQU <>
forc arg, <szTxt>
val1 INSTR <abcdefghijklmnopqrstuvwxyz>, <arg>
if val1 ne 0
sz1 SUBSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, val1, 1
else
sz1 TEXTEQU <arg>
endif
sz2 CATSTR sz2, sz1
ENDM
sz2 CATSTR <'>, sz2, <'>
exitm <sz2>
ENDM


LOWER MACRO szTxt:REQ
LOCAL val1, sz1, sz2
sz2 TEXTEQU <>
forc arg, <szTxt>
val1 INSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, <arg>
if val1 ne 0
sz1 SUBSTR <abcdefghijklmnopqrstuvwxyz>, val1, 1
else
sz1 TEXTEQU <arg>
endif
sz2 CATSTR sz2, sz1
ENDM
sz2 CATSTR <'>, sz2, <'>
exitm <sz2>
ENDM


.data

TstTxt db UPPER(<Test String 32>), 0

TstTxt2 db LOWER (<Test STring 32>),0


.code
start:


invoke MessageBox, 0, addr TstTxt, addr TstTxt2, MB_OK
invoke ExitProcess,0



end start

end

;#################################################


Ah well, if it has any value there it is :alright:
:NaN:
Posted on 2004-05-20 11:59:15 by NaN
Biterider,

Minor error in your @Upper implementation, should be:
; ????????????????????????????????????????

; Macro: @Upper
; Purpose: Converts a symbol string to uppercase.
; Arguments: Symbol string.

@Upper macro String:req
local UpperStr, Letter, Pos, Character

UpperStr textequ <>
% forc Letter, <String>
Pos InStr <abcdefghijklmnopqrstuvwxyz>, <Letter>
if Pos gt 0
Character SubStr <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, Pos, 1
else
Character textequ <Letter>
endif
UpperStr CatStr UpperStr, Character
endm
exitm UpperStr
endm

You forgot to change the:
UpperStr CatStr LowerStr, Character

to
UpperStr CatStr UpperStr, Character

NaN,

Yours adds ' ' to the string, this may be problematic!?!? in some situations ... in other situations I'm sure it had it's uses. Depends on the use I guess! ... for future reference to anyone copying these!

Anyway, Thanx Guys!
Posted on 2004-05-21 03:52:34 by SubEvil