- Регистрация
- 01.02.2012
- Сообщения
- 4 811
- Благодарностей
- 1 187
- Баллы
- 113
Very useful snippet when you want to use action keyboard emulation and want to press, example DOWN button random times.
Another useful snippet for deleting blank lines from .txt file, saw many questions in forum about that
When you working with files copy them or move then you should determine new file location and for that is file extension needed. Quick way to get that.
Get root domain quickly
Count words in text
Count characters
Cheers
C#:
// Generate random nr.
Random r = new Random( );
int countFrom = 5; // Change number to your needed from count
int countTill = 10; // Change number to your needed till count
// Random nr
int randomNr = r.Next(countFrom, countTill);
// What to repeat
string word = "{DOWN}"; // You can change word "{Down}" to whatever you need
// Building string
string repeatWords = String.Concat(Enumerable.Repeat(word, randomNr));
return repeatWords;
C#:
// Delete blank lines from file
string path = project.Variables["filePath"].Value; // Gets file path from your project variable with name "filePath"
var lines = System.IO.File.ReadAllLines(path).Where(arg => !string.IsNullOrWhiteSpace(arg));
System.IO.File.WriteAllLines(path, lines);
return 0;
C#:
// Get file extension
string path = project.Variables["filePath"].Value; // Gets file path from your project variable with name "filePath"
string ext = Path.GetExtension(path);
return ext;
C#:
// Get root domain
var url = project.Variables["url"].Value;
return new Uri(url).Host;
C#:
// Count words in string
var inputstring = project.Variables["text"].Value;
string texttostring = (inputstring);
int count = texttostring.Split(' ').Length;
return count;
C#:
// Count characters
string stringToCount = "Hello World";
return stringToCount.Length.ToString();
Cheers