Page 1 of 1

Replace comma with a dot

Posted: Fri Oct 30, 2020 3:14 pm
by schmitzdp
Hello,

I would like to replace commas by dots in the "productsize" node to get this result: "102.6 Small x 122.6 Big (CM)"

Below, my xml example:

Code: Select all

<order>
	<items>
		<productsize>102,6 Small x 122,6 Big (CM)</productsize>
	</items>
</order>
Do you know the function to do this? Thank you ;)

Re: Replace comma with a dot

Posted: Fri Oct 30, 2020 5:38 pm
by freddyp
This is something you can do directly in the XPath with which you get the info from the XML using an XPath function:
Screen Shot 2020-10-30 at 15.35.00.png
Screen Shot 2020-10-30 at 15.35.00.png (76.96 KiB) Viewed 2690 times
The XPath expression is perhaps not so readable in the image:

Code: Select all

translate(//productsize,',','.')

Re: Replace comma with a dot

Posted: Tue Nov 03, 2020 9:24 am
by schmitzdp
It's even simpler and it works perfectly. Thank you :D

Re: Replace comma with a dot

Posted: Wed Feb 10, 2021 1:48 pm
by schmitzdp
Hello,

is there a similar expression that can modify for example a white space by 3 characters?

Code: Select all

translate(//url,' ','%20')

Re: Replace comma with a dot

Posted: Thu Feb 11, 2021 10:10 am
by freddyp
There is not a similar expression, it is the same expression. The example you give replaces all spaces by %20 in //url.

Re: Replace comma with a dot

Posted: Thu Feb 11, 2021 7:20 pm
by schmitzdp
freddyp wrote:
Thu Feb 11, 2021 10:10 am
There is not a similar expression, it is the same expression. The example you give replaces all spaces by %20 in //url.
No, I tested before posting and all spaces is replaced only by % in //url.

Re: Replace comma with a dot

Posted: Fri Feb 12, 2021 9:55 am
by freddyp
Indeed, my mistake, translate only replaces by the first character. Who ever came up with that idea? There is a replace function but that is only available in XPath 2.0 and Switch uses 1.0.

Before reverting to XSL or scripting I would try this app: https://www.enfocus.com/en/appstore/pro ... ng-replace
The fact that you want to replace a space and not a string like zdhr#$22 will probably make it tricky, but the app has support for regular expressions, so it is worth trying.

Before even doing that, where do you want to use the string? If you use the information in the Parameters property of "HTTP request" for example it will be encoded automatically and spaces will become %20 etc.

And before even doing that, if it is a complete URL that is in your XML, go pull the ears of the person who wrote that URL there without encoding it as such! And do not let go until the problem is fixed at the source.

Re: Replace comma with a dot

Posted: Sun Feb 14, 2021 6:00 pm
by schmitzdp
Thank you for this complete answer. ;)

I was trying to write an url with the name of my file as a variable.

I simply used the "Rename Job" application before writing my url (with Job.NameProper).

I was complicating my life :lol:

Re: Replace comma with a dot

Posted: Mon Mar 01, 2021 5:48 pm
by bleuprocess
There is an app for that!
https://www.enfocus.com/en/appstore/pro ... me-cleaner

If anything is missing, just shout, I actually did write that one ;)