6-line procedure to convert to mixed case

Share your advanced PureBasic knowledge/code with the community.
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

AND51 wrote:Better:

Code: Select all

ProcedureReturn Mid(temp.s, 1, Len(temp.s) - 1) ; no, this is too slow

;Better: Right()
Procedurereturn Right(temp, Len(temp)-1)

; The best way: PeekS() [unicode-compatible!!!)
ProcedureReturn PeekS(@temp+1+#PB_Compiler_Unicode)
I know... :wink: The whole procedure was just a "funny thing" - nothing serious... :D If we want speed, we can also replace FindString with other solutions.
Last edited by techjunkie on Wed Nov 08, 2006 7:13 pm, edited 1 time in total.
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

@techjunkie - doesn't seem to work?

Code: Select all

Procedure.s CapString(st.s) 
    For i= 1 To FindString(st.s, " ", 1) + 1 
      temp.s = temp.s + UCase(Left(StringField(st.s, i, " "), 1)) + LCase(Mid(StringField(st.s, i, " "), 2, Len(StringField(st.s, i, " ")))) + " " 
    Next 
    ProcedureReturn Mid(temp.s, 1, Len(temp.s) - 1) 
EndProcedure 
  Procedure.s CapString2(st.s) 
    For i= 1 To FindString(st.s, " ", 1) + 1 
      temp.s = temp.s + UCase(Left(StringField(st.s, i, " "), 1)) + LCase(Mid(StringField(st.s, i, " "), 2, Len(StringField(st.s, i, " ")))) + " " 
    Next 
    ProcedureReturn temp.s 
  EndProcedure 
string.s = "the QUICK bRoWn fOx jUMPs ovER thE Lazy dog." 
Debug CapString(string)
Debug CapString2(string)
That's using both of your procedures. Cuts off at "jumps".
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Xombie wrote:@techjunkie - doesn't seem to work?
Strange, it works with my PB 4.01... :?: :shock: What result do you get?
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

I'm running 4.01 as well - from the update tool.

Code: Select all

The Quick Brown Fox Jumps
The Quick Brown Fox Jumps 
That's what I get. That's weird. I don't have unicode or anything else enabled.
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Xombie wrote:I'm running 4.01 as well - from the update tool.

Code: Select all

The Quick Brown Fox Jumps
The Quick Brown Fox Jumps 
That's what I get. That's weird. I don't have unicode or anything else enabled.
Hmmm... Same result with that string here too, but this works better...

Code: Select all

Procedure.s CapString(st.s)
  For i = 1 To CountString(st.s, " ") + 1
    temp.s = temp.s + UCase(Left(StringField(st.s, i, " "), 1)) + LCase(Mid(StringField(st.s, i, " "), 2, Len(StringField(st.s, i, " ")))) + " "
  Next
  ProcedureReturn Mid(temp.s, 1, Len(temp.s) - 1)
EndProcedure
  
Debug CapString("the QUICK bRoWn fOx jUMPs ovER thE Lazy dog.")
My misstake, you can't use FindString... *lol*
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Post Reply