PowerShell 및 MS Access를 사용하고 있습니다.수학 인수를 사용하여 문자열 부분 바꾸기
이 열 값의 파이프 내부에 수학 요인을 적용하고 싶습니다.
Ex. factor가 4이면 -100.0은 -400.0이되어야하고 100.0은 400.0이되어야합니다.
"Min_Value"및 "Max_Value"토큰 (하드 코딩 된) 만 수정하면됩니다.
FiledValue는 데이터베이스에서옵니다 (여러 행이 있음).
FieldValue는 항상이 예제와 정확히 동일하지 않지만 토큰 패턴은 항상 동일합니다. 예. Min_Value = | ..... |
function Test
{
$Factor = 4
# Hard-coded SQL query result
$FieldValue = "Min_Value=|-100.0|;Max_Value=|100.0|;COMM_ID1=|1|;"
# Compare this value with a regular expression (Issue A: This doesn't work because of the minus sign and decimal)
if ($FieldValue -match "Min_Value=\|([0-9]+)\|;Max_Value=\|([0-9]+)\|;")
{
# Trying to retreive -100.0 here...(Issue B: this doesn't work). I beleive I can only specify ||, not Min_Value=||
$TokenMinValue = $FieldValue.Split('Min_Value=||')[1]
$TokenMaxValue = $FieldValue.Split('Max_Value=||')[1]
# Trying to take the token (-100.0), multiply it by 4 and write it back where I found it (Issue C: this obvioulsy doesn't work)
$Result = $FieldValue -replace "$regex",($TokenMinValue * $Factor)
$Result = $FieldValue -replace "$regex",($TokenMaxValue * $Factor)
#The goal is for $Result to equal "Min_Value=|-400.0|;Max_Value=|400.0|;COMM_ID1=|1|;"
}
}
은 SQL에서 2 & 3도 가능합니까? – sln
코드는 어디에 있습니까? 지금까지 뭐 해봤 어? – Marusyk
다음은 어떻게 해결 한 것입니까? $ factor = 25.4 $ minRegex = "Min_Value = \ | ([-]? [0-9] * \.? [0-9] *) \ |;" \t $ maxRegex = "Max_Value = \ | ([-]? [0-9] * \.?[0-9] *) \ | 「$ modif = 0 ($ fieldValue의 -match $ minRegex 있으면) {\t \t \t \t \t $ 토큰 = $ 일치 [1] $ 여분 = "= MIN_VALUE | "+ ([변환] :: ToDouble ($ 토큰) * $ 팩터) +"|; " $ fieldValue의 = $ fieldValue의 -replace $ minRegex, $ 교체 \t $ modif = 1 \t \t \t \t \t } // 최대 값을위한 아이디 \t \t \t \t \t \t ($ modif) // UPDATE 쿼리 – Illuna