Up String Help 
Author Message
 Up String Help

DE>>
DE>> I am trying to get a function for making a string uppercase, but the one
DE>> I made is buggy and I can't get it to work (and I'm half asleep too).
DE>> Here is the code I have:
DE>>
DE>> function upstr(s:string):string;
DE>> var x:integer;c:char;
DE>> begin
DE>> repeat
DE>> inc(x);
DE>> c:=upcase(s[x]);
DE>> s[x]:=c;
DE>> writeln(x);
DE>> until x=length(s);
DE>> upstr:=s;
DE>> end;

How about:

function UpStr(S: string): string;
var
   I: byte;

begin
   for I := 1 to Length(S) do S := UpCase(S[I]);
end;

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\

  %         For what purpose is life, if one cannot live freely?         $
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/



Wed, 18 Jun 1902 08:00:00 GMT  
 Up String Help

Quote:

> function UpStr(S: string): string;
> var
>    I: byte;

> begin
>    for I := 1 to Length(S) do S := UpCase(S[I]);
> end;

Silly question. Does anyone know if UpCase pays attention to the
country code and codepage selections?

From the manual entry it would appear not to.

So it might be better to write a routine using INT 21h, function 6521.

Something like this (untested):

Function UpStr(s:string):string;
uses
  dos;
var
  r : regs;
begin
  regs.ax := $6521;
  regs.cx := s[0];
  regs.ds := seg(s[1]);
  regs.dx := ofs(s[1]);
  MsDos(r);
{check r.Flags, if carry set, there's been an error}
  UpStr := S;
end;

Leonard Erickson (aka Shadow)




Wed, 18 Jun 1902 08:00:00 GMT  
 Up String Help

DE>>
DE>> I am trying to get a function for making a string uppercase, but the one
DE>> I made is buggy and I can't get it to work (and I'm half asleep too).
DE>> Here is the code I have:
DE>>
DE>> function upstr(s:string):string;
DE>> var x:integer;c:char;
DE>> begin
DE>> repeat
DE>> inc(x);
DE>> c:=upcase(s[x]);
DE>> s[x]:=c;
DE>> writeln(x);
DE>> until x=length(s);
DE>> upstr:=s;
DE>> end;

How about:

function UpStr(S: string): string;
var
   I: byte;

begin
   for I := 1 to Length(S) do S := UpCase(S[I]);
end;
Opps,  For i := 1 to Length(s) do s[i] := UpCase(s[i]);

                ...red

        -- Kim Forwood --

/-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\


 %
  %         For what purpose is life, if one cannot live freely?        
 $

\-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/



Wed, 18 Jun 1902 08:00:00 GMT  
 Up String Help

TO>FUNCTION UpString (Str : String) : String;
TO> Var
TO>   CharCnt : Byte;
TO>   Temp    : String;
TO> Begin
TO>   Temp := '';
TO>   FOR CharCnt := 1 TO Length(Str) DO Temp := Temp + Upcase(Str[CharCnt]);
TO>   UpString := Temp;
TO> End; { UpString }

TO>Tore Aursand,
TO>Action Computer Systems

The variable Temp is redundant. You can change the characters in Str
directly, and assign thA8final value of Str to UpString upon exit.

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\

  %         For what purpose is life, if one cannot live freely?         $
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. New UPS System 6-8 Hours Continuous Service

2. Ups and Downs of OOP

3. Graphical Mess Ups

4. Ups and Downs of OOP

5. MS SQL6.5 Lock ups

6. pchar := string; string:=pchar

7. How to convert strings to nul-terminated strings?

8. String vs. String literal

9. String within a String

10. String (swapping two chars in a string)

11. Get error when affect a String Field in a string var

12. help on RANDOM and converting int's to strings

 

 
Powered by phpBB® Forum Software