string replace

Moderators: Phil Winkler, Graham Smith, Pete Tabord

string replace

Postby richardjknox » Mon Nov 20, 2017 7:47 pm

Hello All

I Trawled through the forums here, and it Looks like this function not around in FFenics.

I have a field with data in it such as :-

"category1 > category2 > category3"

and I want it to be

category1/category2/category3

Any ideas on a work around to convert this .. any help would be gratefully appreciated

Thanks
rjk
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby Gil Fleming » Mon Nov 20, 2017 11:22 pm

Hi Richard

I think Adrian Jones may have written a search/replace function for one of his workshops.

However, just in case, this procedure will find a target character (oldchar) and replace it with a new character (newchar), using the textpos function to identify the position of the target character, then assembling the two portions to the left and right together with the new character in the middle. I've prompted for the old and new characters to make it a little more multipurpose. Before you use this procedure, I recommend that you do a Save As on your form, and save it with data, just in case something goes wrong.
In my procedure, the form I am working with is Scratchpad2 and the field with the dodgy content is ReplaceSource. Replace them with your form and field names and you are good to go.

Code: Select all
define "oldchar" text 1.
Define "newchar" text 1 .
Define "firstbit" number .
define"lastbit" number .

prompt oldchar "What's the character to be replaced?" .
prompt newchar "What will you replace it with?" .
 for scratchpad2 ;
while textpos ( ReplaceSource ,oldchar) > 0 do
firstbit := textpos ( ReplaceSource ,oldchar) .
lastbit := length(ReplaceSource ) - firstbit .
modify records
ReplaceSource := concat(firstc( ReplaceSource, (firstbit -1)), newchar, lastc(ReplaceSource, lastbit))  .
end
end


Let me know how this works for you. There's an invoice in the post :mrgreen:

ps. your data seems unusual. What kind of app are you writing?
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 

Re: string replace

Postby richardjknox » Tue Nov 21, 2017 9:22 pm

Hi Gil

Thanks for coming back to me, I think I can see how it works, I'll have a go and let you know how I get on.

Regards the reason for doing this ...

..... We get a google output file from our hosting company which we import into ffenics, and use as our stock file. We then format it, and export it out to a csv file and import into our website.

At the moment I just do a search (" > " => "/"), and replace in Excel,to but it would be nice if this was done at source.

The other problem I have is with values over £999 which become eg £1,999.34, I also have do to a search and replace in Excel to get rid of the commas. Is there any way of telling Ffencis NOT to use "," in values > £999 ?

cheers
rjk
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby Gil Fleming » Wed Nov 22, 2017 12:49 am

You could use the StripChar function on your number and put the result in a new text field:

Newtextfield := stripchar(grottycommafield, ",") .
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 

Re: string replace

Postby richardjknox » Thu Nov 23, 2017 9:37 pm

thanks Gil ... didn't know about stripchar .. I'll have a look
cheers
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby richardjknox » Thu Nov 23, 2017 10:01 pm

Hi Gil
Can't find stripchar ... is it something of an add on function ?
cheers
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby Gil Fleming » Thu Nov 23, 2017 11:47 pm

StripChar is an ELF. The associated dll is STRFUNC.DLL. Check to see if you have the dll. If you don't, I can mail it to you.
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 

Re: string replace

Postby richardjknox » Fri Nov 24, 2017 8:44 am

Hi Gil

I can see the dll in the Database Software folder ... so I'll add that to the ELF ..I can see how that works.

I've only got the default ones loaded at the moment ... are there any others worth having ?

Thanks
rjk
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby Gil Fleming » Fri Nov 24, 2017 11:52 am

The ones that are very useful would be:

SetArray() and GetArray() -- Limited to 10 values
SetGlobal() and GetGlobal()
SetUneek() and GetUneek() - good for generating sequential serial numbers
StripChar() -- useful for cleansing data of unwanted punctuation or characters or spaces
TextOut() and TextOutLn() - great for creating individual text files for email bodies or for exporting to different software
FileDelete() -- obvious
FileRename() -- we use this a lot. If you write a procedure to generate an invoice, you can set your DQL to produce a PDF using the converter, but it has to have a predetermined name (invoice.pdf, for example). With Filerename, you can specify the complete path in the rename process, allowing you to rename the file to a unique value (the invoice number) and move it to a specified folder (\invoices).
MessageBoxTimeoutA - produces a message box that will disappear up its own backside after a specified time, but which can be closed via a button before that.
KeyStrokes() has some use if you want to move the cursor around a bit under script control. There is a caveat: if you use the PageUp or PageDown values, the result will depend on the screen resolution.
We have also used the MakeDir functions which can be quite impressive when used as part of a procedure.
Final one of mention is the Wiz utility progress bar - Good if you are emailing documents and want to see the progress on screen.

If you want to email from within ffenics, I would recommend cmdmail for simple stuff, though we have now moved on to Swithmail which is much better. Cmdmail mails can, I think, appear a little malformed to spam detectors, whereas SwithMail sends perfect emails using an existing email account, without the procedure disclosing your email password to anyone who wants a peep under the bonnet (the software hashes your password). This is an excellent security measure and something that even ffenics 2.0 (the daft subscription version) can't do.
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 

Re: string replace

Postby richardjknox » Fri Nov 24, 2017 4:52 pm

Hi Gil
Thanks for this ... I've got STRFUNC.dll in the Database Software folder ... but what parameters do I use in the external function bit .. had trawl round but can't anything on that

StripChar would be very useful to me so any help would be appreciated

cheers
rjk
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby richardjknox » Sun Nov 26, 2017 12:00 am

had a trawl and Adrian had posted info earlier ... all works

many thanks
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby richardjknox » Mon Nov 27, 2017 8:25 pm

Hi Gil

The data in the field is eg:-
Electronics > Computers > Computer Components > Storage Devices > Disk Duplicators > CD/DVD Duplicators

and I need it to be formatted as @-
Electronics/Computers/Computer Components/Storage Devices/Disk Duplicators > CD|DVD Duplicators

So by 'plagiarising' you code and adding a bit too, I got this :-

define "oldchar" text 1 .
Define "newchar" text 1 .
Define "firstbit" number .
define"lastbit" number .
assign oldchar:="/" .
assign newchar:="|" .
--
for feeds
;
while textpos (product_type,oldchar) > 0 do
firstbit := textpos ( product_type, oldchar) .
lastbit := length( product_type ) - firstbit .
modify records
product_type:=concat(firstc(product_type, (firstbit -1)), newchar, lastc( product_type, lastbit)) .
end
end
--
assign oldchar:=">" .
assign newchar:="/" .
--
for feeds
;
while textpos (product_type,oldchar) > 0 do
firstbit := textpos ( product_type, oldchar) .
lastbit := length( product_type ) - firstbit .
modify records
product_type:=concat(firstc(product_type, (firstbit -2)), newchar, lastc( product_type, lastbit-1)) .
end
end

Seems to work, no errors ... takes a while as I have 31k records, any better way of achieving this ?

Thanks for all your help.
rjk
richardjknox
 
Posts: 16
Joined: Thu Jan 20, 2011 1:41 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: string replace

Postby Adrian Jones » Tue Dec 05, 2017 2:52 pm

I do indeed have such a function, and more:

Code: Select all
define "tStr" text 255 .

tStr := "category1 > category2 > category3" .

list records
  tStr ;
  ReplaceAllText ( tStr , " > " , "/" ) .


http://n10net.com/shop/FunctionFactoryStrings.aspx
User avatar
Adrian Jones
 
Posts: 2000
Joined: Tue Sep 11, 2007 2:38 pm
Location: Cornwall, UK
Has thanked: 5 times
Been thanked: 4 times
 

Re: string replace

Postby Gil Fleming » Tue Dec 05, 2017 2:55 pm

Hmmmm. £75.00. I think my solution was a little easier on the wallet :mrgreen:
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 

Re: string replace

Postby Gil Fleming » Tue Dec 05, 2017 3:10 pm

Check your email Adrian.
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 
 

Return to Ffenics 1.x

Who is online

Users browsing this forum: No registered users and 7 guests

cron