static void Main() {
StreamReader sr = File.OpenText(@"D:\mytext.txt");
List<string> data = new List<string>();
while (!sr.EndOfStream)
data.Add(sr.ReadLine());
sr.Close();
StreamWriter sw = new StreamWriter(File.Open(@"D:\mytext.txt", FileMode.Create));
var exp = new List<string>() {"a", "o", "а", "о"};
data = data.Select(s => exp.Contains(s.Trim().ToLower()) ? "1" : s).ToList();
foreach (var v in data)
sw.WriteLine(v);
sw.Close();
}
//....
load: function(callback) {
let loaded = 0;
for (var key in this.sprites)
loaded++;
for (var key in this.sprites) {
this.sprites[key] = new Image();
this.sprites[key].src = 'img/'+ key + '.png';
this.sprites[key].onload = function(){
if(--loaded <= 0)
callback();
}
}
},
start: function() {
this.init();
this.load(this.run);
},
//....
else {
button.getAttribute('disabled', 'disabled');
}
function check2() {
var el = document.querySelectorAll("#input1,#input2,#button");
el[2].disabled = !el[0].value.trim() || !el[1].value.trim();
}
function ss(&$arr,$path,$cur = 0){
if(isset($arr[$path[$cur]])){
$arr[$path[$cur]]["active"] = true;
if($cur+1 < count($path))
ss($arr[$path[$cur]]["children"],$path,$cur+1);
}
}
$arr = array (
array (
'name' => '-1 пункт',
'active' => false,
'children'=> array(),
),
array (
'name' => '0 пункт',
'active' => false,
'children'=> array(),
),
array (
'name' => '1 пункт',
'active' => false,
'children'=> array(
array(
'name' => '1.0 пункт',
'active' => false,
'children' => array(),
),
array(
'name' => '1.1 пункт',
'active' => false,
'children' => array(
array(
'name' => '1.1.0 пункт',
'active' => false,
'children' => array(),
),
array(
'name' => '1.1.0 пункт',
'active' => false,
'children' => array(),
)
),
),
array(
'name' => '1.2 пункт',
'active' => false,
'children' => array(),
),
),
),
array (
'name' => '2 пункт',
'active' => false,
'children'=> array(),
),
);
$path = [ 2,1,1 ];
var_dump($arr);//реузльтат до входа
ss($arr,$path);
var_dump($arr);//реузльтат после входа
array(4) {
[0]=>
array(3) {
["name"]=>
string(13) "-1 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(12) "0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[2]=>
array(3) {
["name"]=>
string(12) "1 пункт"
["active"]=>
bool(false)
["children"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(14) "1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(14) "1.1 пункт"
["active"]=>
bool(false)
["children"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[2]=>
array(3) {
["name"]=>
string(14) "1.2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[3]=>
array(3) {
["name"]=>
string(12) "2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
array(4) {
[0]=>
array(3) {
["name"]=>
string(13) "-1 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(12) "0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[2]=>
array(3) {
["name"]=>
string(12) "1 пункт"
["active"]=>
bool(true)
["children"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(14) "1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(14) "1.1 пункт"
["active"]=>
bool(true)
["children"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
[1]=>
array(3) {
["name"]=>
string(16) "1.1.0 пункт"
["active"]=>
bool(true)
["children"]=>
array(0) {
}
}
}
}
[2]=>
array(3) {
["name"]=>
string(14) "1.2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
}
[3]=>
array(3) {
["name"]=>
string(12) "2 пункт"
["active"]=>
bool(false)
["children"]=>
array(0) {
}
}
}
processArray($value['children'], $key);
$output = array_merge($output,processArray($value['children'], $key));
function loadResources(arr,func){//функция загрузки внешних ресурсов(картинок) arr - массив ссылок, func - функция которая вызовется после загрузки всех ресурсов
var loadStatus = false;
loadStatus = {count: arr.length, loaded: 0, percent: 0};//count - общее количество ресурсов, loaded - сколько загружено ресурсов, percent сколько загружено в процентах
for(var i = 0; i < arr.length; i++){
var tmp = new Image();
tmp.src = arr[i];
tmp.onload = function(){
loadStatus.loaded++;
loadStatus.percent = (loadStatus.loaded * 100)/loadStatus.count;
if(loadStatus.loaded >= loadStatus.count)
func();
}
}
return loadStatus;
}
loadResources(["/img/1.jpg","/img/2.jpg"],draw)
function find($json,$id){
$arr = json_decode($json);
foreach($arr as $v)
if(strval($v->ID) == strval($id))
return true;
return false;
}
$a1 =json_decode('["Яблоко", "Апельсин", "Банан", "Груша"]');
$a2 = json_decode('["Яблоко", "Мандарин", "Банан", "Груша", "Лимон"]');
$added = array_diff($a2,$a1);// Добавлено
$remove = array_diff($a1,$a2);// Убрано
{"Яблоко", "Апельсин", "Банан", "Груша"}, ничего общего с json не имеет
public static void Main()
{
Thread t = new Thread(new ThreadStart(command));
t.Start();
Thread.Sleep(5000);
t.Suspend();
Thread.Sleep(5000);
t.Resume();
Console.ReadKey();
}
public static void command(){
for (var i = 0; i < 10; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(1000);
}
}
public Window()
{
InitializeComponent();
this.textBox.PreviewTextInput += new TextCompositionEventHandler(textBox_PreviewTextInput);
}
void textBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!Char.IsDigit(e.Text,0)) e.Handled = true;
}