KB Article 5198
2005/06/09

Close
X
Contact Tech Support

 Email Tech Support
 (250) 655-1766
 [7:30 - 5:00 PST]
Your Meeting ID will be Provided by a Rep.
Tech Support
Tech Support Home
Software Updates
Knowledge Base Search
Recent KB Articles
Product FAQs
Code Samples
Documentation
Tech Blog
System Requirements
Installation Instructions
Support Testimonials
Contact us to...
Create a Ticket
Request a Free Demo
Suggest a New Feature
Submit Feedback
Upload a Large File
Other Services
Software Training
Professional Services

I need to replace a character in a string with a space and the rplstr function in WebSmart will not accommodate this.

Product: WebSmart ILE Type: Frequently Asked Question

Problem:
Over the years, a number of clients have had the need to use RPLSTR with "" or " " as the newval, but when you do this, you get an error:
 
RNX0100 Length or start position is out of range for the string operation.
In PW_RTS081 procedure  RPLSTR_
 
The solution appeared to be that we add support for blanks and/or spaces in the rplstr function.
 
However, when we researched this, there were some technical constraints (see the bottom if you're interested, a task has been logged for this).  
 
An easy way to do this is to use the SQL scalar replace function.
 
Solution:
Remove spaces:
crtfld(alphafld, 25, 'A');
alphafld= " S p a c e s ";
sqlexec("set :alphafld= replace(:alphafld, ' ', '')";
// alphafld contains "Spaces"
 
Replace with spaces:
crtfld(alphafld, 25, 'A');
alphafld= "Replace_With_Spaces";
sqlexec("set :alphafld= replace(:alphafld, '_', ' ')";
//  alphafld contains "Replace With Spaces"
 
Earlier Solution:
Create a uparser function rplstr2, by copying rplstr from PARSER with the trim() removed from both Old and New parms:
 
 FUNC='rplstr2'
    {
         PROT='ALPHA rplstr2(ALPHA &string, ALPHA &oldval, ALPHA &newval)';
         SRC='
    rplstr_(~&string!:~&oldval!:~ &newval!)';
        RTYPE='ALPHA';
     } 
 
Earliest Solution/Workaround
You can also try this in your code:
 
func rplmethis()
{
 crtfld(mystring, 64, "A", 0, "string");
 crtfld(temp1, 64, "A", 0, "string");
 crtfld(pos1, 2, "N", 0, "counter");
 crtfld(pos2, 2, "N", 0, "position");
 crtfld(quote, 1, "A", 0, "quote");
 crtfld(stringlen, 2, "N", 0, "length of string");
 crtfld(temp2, 64, "A", 0, "string");
 
 pos1 = 1;
 quote = "[";
 mystring = "Pickles are ve[ry green do[n't you know";
 stringlen = len(mystring);
 pos2 = scanstr(quote, mystring,pos1);
 
 if(pos2 > 0)
 {
  temp1 = substr(mystring, pos1, pos2-1) + "";
  
  
  while (pos2 > 0)
  {
   
   pos1 = pos2 + 1;
   pos2 = scanstr(quote, mystring,pos1);
    if(pos2 <> 0)
   {
     temp2 = substr(mystring, pos1, pos2 - pos1);
     temp1 = trim(temp1) + "" + trim(temp2);
    }
    else
    temp1 = trim(temp1) + "" + substr(mystring, pos1, stringlen - pos1 + 1); 
    
   pos2 = scanstr(quote, mystring,pos1);         
   } 
   
 }
}
 
Tech Notes
The reason the RPLSTR function errors out when trying to replace with " " is because the call to rplstr_ trims the parms (in the PARSER member of PW_PSRC).  Therefore the " " is trimmed and thus ends up with length 0. A possible solution to this would be to change the RPLSTR PML function to have additional parms to indicate if the oldval and/or newval should be trimmed, i.e.
 
resstr = rplstr(strval, oldval, trim(*YES, *NO), newval, trim(*YES, *NO));
 
That way, you could pass in " " with *NO for the newval, and it won't trim it, and the RPLSTR function wouldn't error out.
 
MDH 20060127: A better solution will be to create a new function that trims, because at this point we can't change how an existing function works.
 
KJH 20101007. FS Task 6968 has been logged in relation to this.

Rate This Article

Did this example help you to achieve your goal?
 Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

Email Address:
Comments:
Please enable JavaScript in order to rate this page.