Chirurgia cranio-cerebrală minim invazivă
Tehnicile minim invazive impun utilizarea unei tehnologii ultramoderne. Endoscoapele operatorii de diverse tipuri, microscopul operator dedicat, neuronavigația, neuroelectrofiziologia, tehnicile avansate de anestezie, chirurgia cu pacientul treaz reprezintă armamentarium fără de care neurochirurgia prin "gaura cheii" nu ar fi posibilă. Folosind tehnicile de mai sus, tratăm un spectru larg de patologii cranio-cerebrale. www.neurohope.ro |
Powershell: Amesteca cuvintele intre ele cu functia do...while
Last Updated: May 19 2021 13:16, Started by
me_suzy
, May 19 2021 07:25
·
0
#1
Posted 19 May 2021 - 07:25
Buna ziua. Codul meu Powershell trebuie să amestece toate cuvintele, indiferent cate cuvinte sunt, din fisierul file.txt
Functia REPLACE din codul meu nu schimbă prea multe cuvinte între ele. Cred că trebuie să integrez o functie do .. while la codul LOOP. Am găsit acest LINKdar nu stiu cum sa inserez si sa upgradez codul meu ca sa mearga. Sunt la nivel de incepatoare. $fileName = "C:\Folder1\file.txt" $newfilename = "C:\Folder1\newfile.txt" # Get content of file $content = Get-Content -Path $fileName -Raw -Encoding UTF8 $words = (((($content.Split(" ")).Replace(".","")).Replace(",","")).Replace("`n","")) #Define function Function Create-Words { $script:word1 = Get-Random -InputObject $words $script:word2 = Get-Random -InputObject $words Write-Host "First word: " $script:word1 -ForegroundColor Red # output word1 Write-Host "Second word: " $script:word2 -ForegroundColor Cyan # output word2 } # Execute function Create-Words # Replace words randomly $content.Replace("$word1", "$word2") | Out-File -FilePath "$newfilename" -force Edited by me_suzy, 19 May 2021 - 07:26. |
#2
Posted 19 May 2021 - 09:53
Defineste mai clar cerinta.
Ce inseamna sa amestece toate cuvintele? Daca fisierul contine A A A, cum arata amestecat? Dar daca contine A A B? Pornind de la A B C D, este A C B D o solutie valida? |
#3
Posted 19 May 2021 - 09:58
buna ziua, _bcristian. Am definit clar cerinta. Am spus amesteca cuvintele, nu literele.
De exemplu am un text cu 400 cuvinte, dar eu voi da un exemplu scurt aici doar la 7 cuvinte. Merg acasa impreuna cu bunica mea, Ioana. outputul va fi: bunica acasa Ioana Merg mea impreuna cu Edited by me_suzy, 19 May 2021 - 09:58. |
#4
Posted 19 May 2021 - 10:19
Intr-un LOOP, alege un cuvant aleator folosind acel Get-Random, scrie-l in fisierul output; elimina-l din set ($words). Reia loop-ul pana setul este gol.
LE: Poate mai simplu: vad ca Get-Random are optiunea -Shuffle.. Starting in PowerShell 7.1, you can use the Shuffle parameter to return the entire collection in a random order. Edited by Argv, 19 May 2021 - 10:32. |
#5
Posted 19 May 2021 - 12:44
cam asa ceva trebuie. Outputul din noul fiser NewFile.txt este bun, n-am erori la Powershell. Dar la finalul codului n-am mai pus linia asta, fiindca da eroare: `$content | Out-File -FilePath C:\Folder1\NewFile.txt`
((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | Sort-Object {Get-Random} ) -join ' ' | Out-File -FilePath C:\Folder1\NewFile.txt # Get content of file $content = Get-Content -Path $fileName -Raw -Encoding UTF8 $words = (((($content.Split(" ")).Replace(".","")).Replace(",","")).Replace("`n","")) $words.count #Define function Function Create-Words { $script:word1 = Get-Random -InputObject $words # get first random word from word list $script:word2 = Get-Random -InputObject $words # get second random word from word list Write-Host "First word: " $script:word1 -ForegroundColor Green # write output word1 Write-Host "Second word: " $script:word2 -ForegroundColor Magenta # write output of word2 } # Execute function (x times / depending on the word count) # Get the number of words in file $replaceCount = $words.count Edited by me_suzy, 19 May 2021 - 12:46. |
#6
Posted 19 May 2021 - 13:16
era de ajuns doar atat:
((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | Sort-Object {Get-Random} ) -join ' ' | Out-File -FilePath C:\Folder1\NewFile.txt |
Anunturi
▶ 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users