[Console] String-editing

Just starting out? Need help? Post your questions and find answers here.
PureBaser
User
User
Posts: 33
Joined: Mon Apr 10, 2006 8:47 pm
Location: Berlin, Germany
Contact:

[Console] String-editing

Post 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...
PB 4 | WinXP_SP2
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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))
PureBaser
User
User
Posts: 33
Joined: Mon Apr 10, 2006 8:47 pm
Location: Berlin, Germany
Contact:

Post by PureBaser »

Sorry for my late answer. But thank you, its very useful!
PB 4 | WinXP_SP2
Post Reply