Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Value of a string character
Mon, Jan 6 2014 9:02 AMPermanent Link

Matthew Jones

I wish to get this working:
 for i := 0 to Length(RStr)-1 do
 begin
   RStr[i] := RStr[i] xor (Key shr 8);
 ...

The first issue is that RStr[i] is not returning an integer which is needed for the
xor. Chr takes an integer and makes a character. Casting doesn't work. Anyone know
how to get the numeric value?  

Second, the text says that strings are immutable. Do I need to care about this here?
It says I can't change things in-situ, but must copy. Presumably I could have an
empty string and append the calculated value to it (using chr). Or does EWB
actually hide this from me? I don't think I've noticed this before, and I'd be
surprised if I hadn't done string edits before.
   
/Matthew Jones/
Mon, Jan 6 2014 11:13 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/6/2014 9:02 AM, (Matthew Jones) wrote:
> The first issue is that RStr[i] is not returning an integer which is needed for the
> xor.

That would make using string and extracting characters not useable Frown

> how to get the numeric value?

Use Ord()

So something like : Ord(RStr[i]) xor (Key shr 8);


> Second, the text says that strings are immutable. Do I need to care about this here?
> It says I can't change things in-situ, but must copy. Presumably I could have an
> empty string and append the calculated value to it (using chr). Or does EWB
> actually hide this from me? I don't think I've noticed this before, and I'd be
> surprised if I hadn't done string edits before.

Yes it does affect you - AFAIK EWB hides the string level operations
(for example appending strings and assigning back to one) but you can't
do character replacement like you want (i.e. RStr[i] := ...).
Doing append is probably best way to deal with this (  RStr2 :=  RStr2 +
Chr(...)) or alternative is to use Array of Char (in theory could be
faster but i highly doubt you'd notice so string would be simpler)

Raul
Mon, Jan 6 2014 11:28 AMPermanent Link

Matthew Jones

>  Anyone know
> how to get the numeric value?  

Ord(). Why didn't I think of that!

And the compiler complains with the assignment to the string position.

/Matthew Jones/
Mon, Jan 6 2014 12:00 PMPermanent Link

Matthew Jones

> So something like : Ord(RStr[i]) xor (Key shr 8);

I think I had to put in an extra set of parenthesis for some operation or other,
but you are spot on on everything else. Thank you.

/Matthew Jones/
Mon, Jan 6 2014 1:25 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< The first issue is that RStr[i] is not returning an integer which is
needed for the xor. Chr takes an integer and makes a character. Casting
doesn't work. Anyone know how to get the numeric value? >>

As Raul noted - Ord():

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb1&topic=Ord

<< Second, the text says that strings are immutable. Do I need to care about
this here? It says I can't change things in-situ, but must copy. Presumably
I could have an empty string and append the calculated value to it (using
chr). Or does EWB actually hide this from me? I don't think I've noticed
this before, and I'd be surprised if I hadn't done string edits before. >>

What you want is the TStringBuilder class in the WebCore unit.  It's not
documented yet, but will be in 1.03.  But, it's pretty self-explanatory and
allows you to do in-place character manipulation and assignment.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 6 2014 1:59 PMPermanent Link

aberas

By the way, Tim, how is 1.03 coming?
Are we going to get our late christmas present? Smile





"Tim Young [Elevate Software]" wrote:

Matthew,

<< The first issue is that RStr[i] is not returning an integer which is
needed for the xor. Chr takes an integer and makes a character. Casting
doesn't work. Anyone know how to get the numeric value? >>

As Raul noted - Ord():

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb1&topic=Ord

<< Second, the text says that strings are immutable. Do I need to care about
this here? It says I can't change things in-situ, but must copy. Presumably
I could have an empty string and append the calculated value to it (using
chr). Or does EWB actually hide this from me? I don't think I've noticed
this before, and I'd be surprised if I hadn't done string edits before. >>

What you want is the TStringBuilder class in the WebCore unit.  It's not
documented yet, but will be in 1.03.  But, it's pretty self-explanatory and
allows you to do in-place character manipulation and assignment.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 6 2014 2:35 PMPermanent Link

Walter Matte

Tactical Business Corporation

See ...

http://www.elevatesoft.com/forums?action=view&category=ewb&id=ewb_general&page=1&msg=4109#4109


aberas wrote:

By the way, Tim, how is 1.03 coming?
Are we going to get our late christmas present? Smile





"Tim Young [Elevate Software]" wrote:

Matthew,

<< The first issue is that RStr[i] is not returning an integer which is
needed for the xor. Chr takes an integer and makes a character. Casting
doesn't work. Anyone know how to get the numeric value? >>

As Raul noted - Ord():

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb1&topic=Ord

<< Second, the text says that strings are immutable. Do I need to care about
this here? It says I can't change things in-situ, but must copy. Presumably
I could have an empty string and append the calculated value to it (using
chr). Or does EWB actually hide this from me? I don't think I've noticed
this before, and I'd be surprised if I hadn't done string edits before. >>

What you want is the TStringBuilder class in the WebCore unit.  It's not
documented yet, but will be in 1.03.  But, it's pretty self-explanatory and
allows you to do in-place character manipulation and assignment.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Image