New topic: 

Build and array out of a string....

<http://forums.realsoftware.com/viewtopic.php?t=31422>

       Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic         Author  
Message       JustSomeGuy           Post subject: Build and array out of a 
string....Posted: Fri Dec 04, 2009 9:15 pm                               
Joined: Fri May 11, 2007 11:35 am
Posts: 669              In C++ I wrote this to achieve my goal of building an 
array out of this string:
Code:sscanf(buf, "%f%*c%f", &Elem[0], &&Elem[1]);For a string that looks like 
this in RB:
Code:dim s as String = "3.4375\3.4375"The c++ code isn't that great because it 
assumes there will only be two floats...
I think it would be easy use NthField... or splitCode:NthField(s, "\", n)Where 
n is the element of the array your want.Code:Dim anArray(-1) as String
anArray=Split(s, "\")
but then I have to create another array which is the single values...
Suggestions?     
_________________
A picture paints a thousand words.
A thought paints a thousand pictures.  
                            Top               timhare           Post subject: 
Re: Build and array out of a string....Posted: Fri Dec 04, 2009 10:31 pm        
                
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6888
Location: Portland, OR  USA              How about using the For Each syntax 
that works with arrays.
Code:dim anArray() as Single
for each t as string in Split(s, "\")
  anArray.append CDbl(t)
next


Tim   
                            Top               brisance           Post subject: 
Re: Build and array out of a string....Posted: Fri Dec 04, 2009 10:35 pm        
                
Joined: Tue Oct 06, 2009 2:38 am
Posts: 26              According to the IDE help notes for the "for...each" 
keyword:

Quote:The user should not make any assumptions of the traversal order as it is 
subject to change in the future.   
                            Top                npalardy           Post subject: 
Re: Build and array out of a string....Posted: Fri Dec 04, 2009 10:47 pm        
                
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 5460
Location: Canada, Alberta, Near Red Deer              All that means is you 
have no idea if it's first to last, last to first or random
But every element will be dealt with once     
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                            Top               timhare           Post subject: 
Re: Build and array out of a string....Posted: Fri Dec 04, 2009 10:57 pm        
                
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6888
Location: Portland, OR  USA              That is a valid point, though.  If 
order is important, as is implied by the OP, then for each may not be the best 
choice.  It works for now and there is no reason to expect it to change, but RS 
has covered their backsides if some unintended side effect of some future 
change causes it to be different.  Caveat emptor.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to