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.


OK, next string question


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2007, 10:16 AM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default OK, next string question

Hi, again a string question. I am working on a datastring replacing and deleting characters which I dont want but the StrRemove and StrReplace function doesnt work in the following example

D$ = "1, 0" & CRLF & "2, 0" & "3, 0) & CRLF 'spaces after comma intended

For i = 0 to StrLength(D$)-1
k = StrAt(D$,i)
IF k = " " then 'also ASC(k) = 32 and k = chr(32) dont work
StrRemove(D$," ", 1)
END IF
NEXT

(The reason I am using this FOR next loop is that it also checks for TABS and commas but this code is not included here)
Now the program passes the IF then condition but doesnt remove (or replace the space with another character). Is this due to the FOR NEXT condition in which the string function is stored and if yes how do I edit a string in a function in which the string itself is examined? Or could it be that a DO WHILE {as long as there are spaces in this string -> remove them} function works better, and if yes how do I state the condition to be fulfilled?
I can imagine that after editing, the D$ and i-counter isnt updated in the FOR NEXT loop.
thnx again
Marc
Reply With Quote
  #2 (permalink)  
Old 06-07-2007, 10:30 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,560
Default

All the string keywords return a new string.
You should use:
D$ = StrRemove(D$...)
Reply With Quote
  #3 (permalink)  
Old 06-07-2007, 10:40 AM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default

Erel, OK, I understand, but then I am getting an IndexOutOfRangeException with the k = StrAt(D$,i) statement... the i-counter CAN go past the string if it is shortened truncated in the loop, yes?
Reply With Quote
  #4 (permalink)  
Old 06-07-2007, 11:03 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,560
Default

No. You can't get a character that doesn't exist.
Just add i = i - 1 after the StrRemove.
Reply With Quote
  #5 (permalink)  
Old 06-07-2007, 11:23 AM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default

hmmmm..... error still exist....
Reply With Quote
  #6 (permalink)  
Old 06-07-2007, 11:54 AM
Junior Member
 
Join Date: May 2007
Posts: 45
Default

Hi, I don't thing that you can solve the problem by decrementing i, because the end condition for " For - Next " loop remains still the same. I thing, you should use strReplace(D$," ","") for removing spaces ( if I understand correct what do you want ).
Petr
Reply With Quote
  #7 (permalink)  
Old 06-07-2007, 11:57 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,560
Default

Petr you are right .
Still it is important to decrease i, otherwise it will skip some characters.
The solution is to use a While loop.
Do While i < StrLength(D$)
...
i = i + 1
Loop
Reply With Quote
  #8 (permalink)  
Old 06-07-2007, 12:04 PM
Junior Member
 
Join Date: May 2007
Posts: 45
Default

Yes, and maybe it could be done by the other way :

If strIndexOf(D$," ",0) <> -1 then D$ = strReplace(D$," ","")

And you don't need to use any loop.

Petr
Reply With Quote
  #9 (permalink)  
Old 06-07-2007, 12:24 PM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default

Gents,

I will try this. It looks good!
thnx for the input!
Marc
Reply With Quote
  #10 (permalink)  
Old 06-07-2007, 01:12 PM
Senior Member
 
Join Date: Apr 2007
Posts: 192
Default

Works!!!
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
String and Shell questions HARRY Questions & Help Needed 4 12-18-2007 05:56 PM
Remove spaces from string forisco Questions & Help Needed 2 11-16-2007 10:07 AM
checking textbox string derez Questions & Help Needed 13 10-25-2007 11:58 AM
Get a input string from user vinians Questions & Help Needed 10 09-04-2007 10:43 PM
Basic string operators Rioven Questions & Help Needed 2 06-10-2007 08:24 AM


All times are GMT. The time now is 09:52 AM.


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