![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Is there a function to remove Spaces from the Beginning and end of a String?
Looked through the help file in Strings and dont see any function for that. |
|
||||
|
I have resolved this way:
Code:
Sub fncALLTRIM(xString)
If StrLength(xString) < 1 Then Return ""
xs = fncLTRIM(xString)
xs = fncRTRIM(xs)
Return xs
End Sub
Sub fncLTRIM(xString)
If StrLength(xString) < 1 Then Return ""
xs = xString
rLTRIM:
If StrLength(xs) > 0 Then
If SubString(xs, 0, 1) = Chr(32) Then
xs = SubString(xs, 1, StrLength(xs) - 1)
Goto rLTRIM
End If
End If
Return xs
End Sub
Sub fncRTRIM(xString)
If StrLength(xString) < 1 Then Return ""
xs = xString
rRTRIM:
If StrLength(xs) > 0 Then
If SubString(xs, StrLength(xs) - 1, 1) = Chr(32) Then
xs = SubString(xs, 0, StrLength(xs) - 1)
Goto rRTRIM
End If
End If
Return xs
End Sub
![]() In my projects, exposed in "Italian Forum", you will find other examples and functions... Regards. Last edited by maXim : 08-31-2007 at 09:09 AM. |
|
||||
|
Hi maXim,
just as a small hint, there is no need to code the ugly ( ) keyword Goto.The Do While function in connection with the Exit statement is a much better solution: Code:
Sub fncLTRIM(xString)
If StrLength(xString) < 1 Then Return ""
xs = xString
Do While StrLength(xs) > 0
If SubString(xs, 0, 1) = Chr(32) Then
xs = SubString(xs, 1, StrLength(xs) - 1)
Else
Exit
End If
Loop
Return xs
End Sub
specci48 |
|
||||
|
Hi specci48,
sorry for my English but not for my example...Your observation is correct but the cycle DO WHILE ... LOOP results to be slower than around 0,25uS in comparison to the simple GOTO! (verified on my PPC: Acer n30). I don't believe that this is a problem HW since all the compilers suffer of it... Regards. |
|
|||
|
Great solutions for trimming the excess spaces from begging and trailing.
Thank you for sharing them. I had a thought about just passing the string using StrAt to find the first and last Character that was not a space and then use SubString on those two numbers? "...Clarendon Red...." The full points at begin and end of above represent spaces (. to make visible for example). StrAt shows the first 3 as spaces and the 4th one as a non Space and sets the start location at 3 - the StrAt func then finds the last NON space to be at position 15 - SubString "...Clarendon Red....", FirstPos, SecondPos-FirstPos) Would that technique be a fast operation with the processor? |
|
|||
|
Quote:
an script for removing the html tags. let me know if you got one. thanks Last edited by tvrman : 08-31-2007 at 02:56 PM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Problems - Images must not include spaces | J12345T | Bug Reports | 8 | 06-01-2008 07:55 AM |
| esiste la funzione trim? | marcomarco | Italian Forum | 2 | 04-16-2008 08:03 AM |
| SORT / TRIM Table(CSV) | sintaq | Questions & Help Needed | 1 | 03-24-2008 09:52 AM |
| Remove spaces from string | forisco | Questions & Help Needed | 2 | 11-16-2007 10:07 AM |
| Externalization of strings for localisation | Tirs | Questions & Help Needed | 2 | 05-29-2007 10:19 PM |