New topic: 

StrComp Question

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

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        DanSandbergUCONN          Post subject: StrComp QuestionPosted: 
Thu Jan 17, 2013 1:46 pm                         
Joined: Fri Dec 21, 2007 9:50 am
Posts: 215                Hi All -

This is more of a general question about strings. I have a large array of data, 
and SOMETIMES the data for a single field will have quotes hugging it. So it 
looks like,

Val1, Val2, "Val3", Val4, "Val5", Val6, ....

Now... If there were leading and trailing exclamation points (!) around the 
values, for example, I would use the split function with the null string as the 
delimiter, breaking the sequence into a series of single characters, and I 
would then reconstruct the string skipping the first and last character ONLY if 
strcomp("!", string_array(0),1)=0 (i.e. if the first character were an 
exclamation point). SO code would look like string_array()=split(myvalue,"")
if strcomp(string_array(0),"!")=0 then
  for i=1 to ubound(string_array)
  newString=newString+string_array(i)
  next
else
  for i=0 to ubound(string_array)
  newString=myvalue
  next
end if





But I can't use this method with the " character because """ creates one null 
string and one open parenthesis. 

Any ideas? Thanks.

EDIT: I know in C++ there is an escape character to signify that the character 
following it is to be treated as a string and NOT meant to close the quote. I 
do not know if this is the case in RB.   
                             Top                charonn0          Post subject: 
Re: StrComp QuestionPosted: Thu Jan 17, 2013 2:15 pm                            
     
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1071
Location: San Francisco, CA, USA                DanSandbergUCONN wrote: I know 
in C++ there is an escape character to signify that the character following it 
is to be treated as a string and NOT meant to close the quote. I do not know if 
this is the case in RB.



The escape character in RB for double-quote characters is another double-quote 
character. To create a string containing a single double-quote character, use 
four double-quote characters:
string_array()=split(myvalue,"""")
Breaking it down to its parts:
"  <--- begin a sting literal
""   <--- one double quote mark that does not terminate the string literal
"  <--- terminate string literal

Alternatively, you can use the Chr method to specify the codepoint of the 
character in question. In ASCII the double-quote character is character 34, so:

string_array()=split(myvalue,Chr(34))      
_________________
Boredom Software  
                             Top                DaveS          Post subject: 
Re: StrComp QuestionPosted: Thu Jan 17, 2013 4:01 pm                            
     
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4423
Location: San Diego, CA                off the top of my head

dim v() as string
dim i as integer
dim q as string
dim ptr as integer
ptr=1
q="*"
for i=1 to len(myvalue)
  if mid(myvalue,i,1)=chrb(34) then
  if q="*" then
  q=chrb(34)
  else
  q="*"
  end if
  end if
  if q="*" and mid(myvalue,i,1)="," then
  v.append mid(myvalue,ptr,i-1)
  ptr=i+1
  end if
next i
      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                DanSandbergUCONN          Post 
subject: Re: StrComp QuestionPosted: Thu Jan 17, 2013 5:45 pm                   
      
Joined: Fri Dec 21, 2007 9:50 am
Posts: 215                Thank you both. Either the escape character of 
chr(34) would obviously be easy to implement. Much appreciated.   
                             Top                timhare          Post subject: 
Re: StrComp QuestionPosted: Thu Jan 17, 2013 6:28 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11992
Location: Portland, OR  USA                If you have a value like

"Val1"

and you want to strip the beginning and ending quotes, you can do it much 
simpler:
if left(myvalue, 1) = chr(34) then
  myvalue = mid(myvalue, 2, len(myvalue)-2)
end
   
                             Top                ktekinay          Post subject: 
Re: StrComp QuestionPosted: Thu Jan 17, 2013 7:04 pm                            
     
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 362
Location: New York, NY                Tim is correct. Also, if you want to 
concatenate the elements of a string array, Join is much faster than "v = v + 
arr( i )".

FYI, I have an "Unquoted" method in my M_String module, available at my web 
site. It will work on either a single string or a string array, and will work 
exactly as you want, stripping the quotes only from those values that are 
actually quoted.      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 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