Имя пользователя:
Пароль:
 

Название темы: [решено] рэндом
Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Цитата null999:
кодировка юникод »
Ну, вот. О чём, собственно, и речь.

Пробуйте так:
Скрытый текст
Код: Выделить весь код
Option Explicit

Const ForReading   = 1
Const TristateTrue = -1


Dim strSourceFile

Dim strContent

Dim objRegExp


If WScript.Arguments.Count = 1 Then
	strSourceFile = WScript.Arguments.Item(0)
	
	With WScript.CreateObject("Scripting.FileSystemObject")
		If .FileExists(strSourceFile) Then
			With .OpenTextFile(strSourceFile, ForReading, False, TristateTrue)
				strContent = .ReadAll()
				.Close
			End With
			
			Set objRegExp = WScript.CreateObject("VBScript.RegExp")
			
			With objRegExp
				.IgnoreCase = True
				.Global     = True
				.Pattern    = "мама"
			End With
			
			If objRegExp.Test(strContent) Then
				.CopyFile strSourceFile, .GetBaseName(strSourceFile) & ".bak" ,True
				
				Randomize Timer
				
				With .CreateTextFile(strSourceFile, True, True)
					.Write objRegExp.Replace(strContent, Array("Мама", "мыла", "раму")(Int(Rnd * 3)))
					.Close
				End With
			Else
				WScript.Echo "Pattern [" & objRegExp.Pattern & "] not found in content of source file [" & strSourceFile & "]."
				WScript.Quit 3
			End If
			
			Set objRegExp = Nothing
		Else
			WScript.Echo "Can't find source file [" & strSourceFile & "]."
			WScript.Quit 2
		End If
	End With
Else
	WScript.Echo "Usage: cscript.exe //nologo """ & WScript.ScriptName & """ <Source file>"
	WScript.Quit 1
End If

WScript.Quit 0

Отправлено: 11:12, 18-10-2016 | #8

Название темы: [решено] рэндом