Page 1 of 1

[Console] String-editing

Posted: Mon May 22, 2006 5:40 pm
by PureBaser
Hi!

I need a bit help.
I have a string called a$. And I want to find or replace the LAST Space-Sign. Findstring only give me the first sign. Maybe I can switch the String in the swap order, that means instead a$="ABC", it should be a$ ="CBA"?! The brackground-idea is, that I'm writing a Console-Text-Procedure. After the last known Space-Sign in a line, the Text automatic go to a new line...

Posted: Mon May 22, 2006 6:21 pm
by Trond

Code: Select all

Procedure LastSpace(s.s)
  Protected Last = 0
  Protected Length = Len(s)
  Protected I
  While I < Length
    If PeekC(@s + I) = ' '
      Last = I+1
    EndIf
    I + SizeOf(Character)
  Wend
  ProcedureReturn Last/SizeOf(Character)
EndProcedure


a.s = "The quick brown fox jumps over the lazy dog"
Debug Right(a.s, Len(a)-LastSpace(a))

Posted: Wed May 24, 2006 2:45 pm
by PureBaser
Sorry for my late answer. But thank you, its very useful!