Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Trim Spaces from Beginning and end of Strings


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 08-31-2007, 08:07 PM
Junior Member
 
Join Date: Apr 2007
Location: Qld, Australia
Posts: 42
Default

tvrman - here is the code I use for stripping the HTML Markup.

Pass the sub a Line of HTML

Code:
Sub DecodeTxt(TheTxt)
	
    tmp = ""
    ch=""	
    leng = StrLength(TheTxt)
    AON = false
    For i = 0 To leng-1
        ch = StrAt(TheTxt, i)
        If (AON = false) Then
            If (ch = "<") Then
                AON = true
            Else
                ' insert the char into text to save
                tmp = tmp & ch
            End If
        Else
            If (ch = ">") Then 
	    AON = false
            End If
        End If ' else if AON is false (true) 
    Next
'	TextConvert = LTRIM$(RTRIM$(tmp))	
    Return tmp
End Sub
I have taken this from C++ which I have been using for quite a while, and converted it to B4PPC use.
Reply With Quote
  #12 (permalink)  
Old 09-01-2007, 11:06 AM
Senior Member
 
Join Date: May 2007
Posts: 130
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi, I did like this...
s value should not be blank
PHP Code:
s=" LTRIM RTRIM  "
'LTRIM
lt=StrRemove (s, 0, StrIndexOf  (s, StrAt(StrReplace(s," ",""),0),0))

'
RTRIM
s
=lt
rl
=StrLength(s)
i=rl
Do While StrAt(s,i-1)=" "
i=i-1
If StrAt(s,i-1)<>" " Then Exit
Loop 
rt
=StrRemove(s,i,rl-i
__________________
Rioven

Sony Ericsson XPERIA X1i WM6.1
480x800 Display Resolution
with QWERTY keyboard
Reply With Quote
  #13 (permalink)  
Old 09-01-2007, 11:34 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,134
Default

After reading this thread I understand that it is a good time to build a Regular Expressions library
Reply With Quote
  #14 (permalink)  
Old 09-01-2007, 11:50 AM
maXim's Avatar
Senior Member
 
Join Date: May 2007
Location: Florence, Italy
Posts: 155
Send a message via MSN to maXim Send a message via Skype™ to maXim
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Erel,

I approve Your decision!

For when the new Library?

Regards.
Reply With Quote
  #15 (permalink)  
Old 09-01-2007, 01:32 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,134
Default

I hope that it will be released in a week or two.
Reply With Quote
  #16 (permalink)  
Old 09-01-2007, 04:37 PM
maXim's Avatar
Senior Member
 
Join Date: May 2007
Location: Florence, Italy
Posts: 155
Send a message via MSN to maXim Send a message via Skype™ to maXim
Awards Showcase
Beta Tester 
Total Awards: 1
Post

Hi Erel,

Thanks for Your Job!

I don't know well unfortunately the english, but If You need a beta-tester i’m ready for You!

Regards.

Massimo
Reply With Quote
  #17 (permalink)  
Old 09-01-2007, 05:43 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,134
Default

Thanks. And I don't worry about your English as RegEx works on any given string
Reply With Quote
  #18 (permalink)  
Old 09-01-2007, 09:58 PM
Knows the basics
 
Join Date: May 2007
Posts: 60
Default

Quote:
Originally Posted by BPak View Post
tvrman - here is the code I use for stripping the HTML Markup.

Pass the sub a Line of HTML

Code:
Sub DecodeTxt(TheTxt)
	
    tmp = ""
    ch=""	
    leng = StrLength(TheTxt)
    AON = false
    For i = 0 To leng-1
        ch = StrAt(TheTxt, i)
        If (AON = false) Then
            If (ch = "<") Then
                AON = true
            Else
                ' insert the char into text to save
                tmp = tmp & ch
            End If
        Else
            If (ch = ">") Then 
	    AON = false
            End If
        End If ' else if AON is false (true) 
    Next
'	TextConvert = LTRIM$(RTRIM$(tmp))	
    Return tmp
End Sub
I have taken this from C++ which I have been using for quite a while, and converted it to B4PPC use.


Thanks!!! Bpak
It works very good.
Reply With Quote
  #19 (permalink)  
Old 09-09-2007, 02:28 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,134
Default

Using the new Regex library:
Code:
'Regex1 is a Regex object and Match1 is a Match object.
Sub Globals
End Sub
 
Sub App_Start
 Match1.New1
 Regex1.New1("(?<=^\s*)\w.*\w|\w(?>=\s*)")
 Msgbox(Trim(" some string with spaces "))
End Sub
 
Sub Trim(s)
 Match1.Value = Regex1.Match(s)
 Return Match1.String
End Sub
Reply With Quote
  #20 (permalink)  
Old 03-24-2008, 02:53 AM
Newbie
 
Join Date: Mar 2008
Posts: 6
Default Trim function

Code:
Sub trim(txt)

	ch = SubString(txt, 0, 1)
	
	Do While Asc(ch) < 33
		txt = SubString(txt, 1, StrLength(txt)-1)
		ch = SubString(txt, 0, 1)
	Loop
	
	ch = SubString(txt, StrLength(txt)-1, 1)
	
	Do While Asc(ch) < 33
		txt = SubString(txt, 0, StrLength(txt)-1)
		ch = SubString(txt, StrLength(txt)-1, 1)
	Loop
	
	Return txt
	
End Sub
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Problems - Images must not include spaces J12345T Bug Reports 8 06-01-2008 08:55 AM
esiste la funzione trim? marcomarco Italian Forum 2 04-16-2008 09:03 AM
SORT / TRIM Table(CSV) sintaq Questions & Help Needed 1 03-24-2008 10:52 AM
Remove spaces from string forisco Questions & Help Needed 2 11-16-2007 11:07 AM
Externalization of strings for localisation Tirs Questions & Help Needed 2 05-29-2007 11:19 PM


All times are GMT. The time now is 04:51 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0