Replace comma with a dot

Post Reply
schmitzdp
Member
Posts: 23
Joined: Thu Aug 06, 2020 1:36 pm

Replace comma with a dot

Post by schmitzdp » Fri Oct 30, 2020 3:14 pm

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 ;)

freddyp
Advanced member
Posts: 620
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » Fri Oct 30, 2020 5:38 pm

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 3000 times
The XPath expression is perhaps not so readable in the image:

Code: Select all

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

schmitzdp
Member
Posts: 23
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Tue Nov 03, 2020 9:24 am

It's even simpler and it works perfectly. Thank you :D

schmitzdp
Member
Posts: 23
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Wed Feb 10, 2021 1:48 pm

Hello,

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

Code: Select all

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

freddyp
Advanced member
Posts: 620
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » 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.

schmitzdp
Member
Posts: 23
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Thu Feb 11, 2021 7:20 pm

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.

freddyp
Advanced member
Posts: 620
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » Fri Feb 12, 2021 9:55 am

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.

schmitzdp
Member
Posts: 23
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Sun Feb 14, 2021 6:00 pm

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:

bleuprocess
Newbie
Posts: 2
Joined: Wed Nov 23, 2011 10:43 am
Contact:

Re: Replace comma with a dot

Post by bleuprocess » Mon Mar 01, 2021 5:48 pm

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 ;)

Post Reply