PALES
PALES

Reputation: 7

Find and replace "." character

There are some folder. For example 0.8, 0.9, 1.0. Between the these name max number is 1.0. Actually ı can find value. But I want to write as "1.0" format to .txt file.

$maxvalue = ($var | Measure -Max).Maximum
 $vers = 'v'+$maxvalue

find the max value in $var strings. When I want to bring 'v' character to this name it looks like v1. But I want to be like v1.0 for other file process in my code. How can protect this name with ".0" caracter and add text file. Thanks for your support

Upvotes: 0

Views: 52

Answers (1)

Theo
Theo

Reputation: 61068

If in your current locale settings, you use the decimal point (.), this should do it:

$vers = 'v{0:F1}' -f $maxvalue

However, if (like it is for me), the current locale setting is e decimal comma (,), you need to either temporarily set the current culture to for instance 'en-US':

$oldCulture = [cultureinfo]::CurrentCulture
[cultureinfo]::CurrentCulture = 'en-US'
$vers = 'v{0:F1}' -f $maxvalue
[cultureinfo]::CurrentCulture = $oldCulture

Or do:

$vers = 'v' + $maxvalue.ToString("F1",[cultureinfo]::InvariantCulture)

Please also have a look at the excellent explanation by mklement0

Upvotes: 1

Related Questions