小编Axe*_*eem的帖子

在c ++中搜索和替换txt文件中的字符串

我想在文件中找到一个字符串,并用用户输入替换它.
这是我的粗略代码.

#include <iostream>
#include <fstream.h>
#include <string.h>

int main(){
    istream readFile("test.txt");

    string readout,
         search,
         replace;

    while(getline(readFile,readout)){
        if(readout == search){
            // How do I replace `readout` with `replace`?
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更新
这是解决我的问题的代码

的test.txt:

id_1
arfan
haider

id_2
saleem
haider

id_3
someone
otherone
Run Code Online (Sandbox Code Playgroud)

C++代码:

#include <iostream>
#include <fstream>
#include <string>

using namesapce std;

int main(){
    istream readFile("test.txt");
    string readout,
           search,
           firstname,
           lastname;

    cout << "Enter the id which you want to modify";
    cin >> search;

    while(getline(readFile,readout)){
        if(readout == search){
            /* …
Run Code Online (Sandbox Code Playgroud)

c++ search replace file

5
推荐指数
2
解决办法
5万
查看次数

php __set(),__ get和简单的seting,获取函数之间的区别

我不确定在PHP 中使用__get__set方法有什么价值.

这是在数组中设置值的代码.

class myclass {
public $sotre = array();

public function __set($arraykey,$value){
    echo 'Setting '.$arraykey.' to '.$value;
    $this->store[$arraykey] = $value;
} 
}

$obj = new myclass;
$obj->a = 'arfan';
Run Code Online (Sandbox Code Playgroud)

这是另一个代码.

 class myclass {
public $sotre = array();

public function setvalue($arraykey,$value){
    echo 'Setting '.$arraykey.' to '.$value;
    $this->store[$arraykey] = $value;
} 
}

$obj = new myclass;
$obj->setvalue('a','arfan');
Run Code Online (Sandbox Code Playgroud)

这两个函数都做同样的事情.

代码使用__get/ __setmagic方法:

class myclass {
public $store = 
array(
    'a'=>'arfan',
    'b'=>'azeem',
    'c'=>'hader'
);

public function __get($arraykey){ …
Run Code Online (Sandbox Code Playgroud)

php oop magic-methods

4
推荐指数
1
解决办法
4231
查看次数

使用javascript选择具有相同标签名称的所有元素,并部分突出显示内容

我做了一个代码,应该突出搜索字符串,但它不起作用.
这是代码:

<body>

  <div>div is here</div>
   <div id="divid">

    <div>this is a div 1</div>
    <div> this is a div 2</div>
    <div> this is a div3</div>

  </div>

  <div> another div is here</div>
  </body>  
Run Code Online (Sandbox Code Playgroud)

这是一个javascript代码.

  function checkit(){

var hlWord = "div";
        var nregex = new RegExp(hlWord,"gi");
        var div = document.getElementById("divid").getElementsByTagName('div');

        for(var i=0; i <= div.length; i++){

            var div1 = div[i].innerHTML;

            var rword = div1.replace(nregex,"<b>"+hlWord+"</b>");
            div1.innerHTML = rword;

        }


  }  
Run Code Online (Sandbox Code Playgroud)

html javascript highlight

2
推荐指数
1
解决办法
1485
查看次数

PHP Magic Method __unset()不能用于调用unset函数

我不明白为什么__unset()不工作.

class myclass {
    public $name = array();

    public function __set($arraykey, $value){
        $this->name[$arraykey] = $value;
    }

    public function __isset($argu){
        return isset($this->name[$argu]);
    }

    public function __unset($argu){ 
        echo "Working: Unset $this->name[$argu]";
        unset($this->name[$argu]);
    }
}

$obj = new myclass;
$obj->name = 'Arfan Haider';

var_dump(isset($obj->name));

unset($obj->name);
Run Code Online (Sandbox Code Playgroud)

我读到只要unset()调用该函数,就会__unset()自动调用Magic Method 并取消设置变量.

在上面的代码我使用unset但它没有调用__unset().为什么?我在理解魔术方法时遗漏了什么__unset()

php magic-methods unset

2
推荐指数
1
解决办法
2407
查看次数

更改浏览器栏中的网址而不重新加载页面

我想在不重新加载页面的情况下更改浏览器栏中的URL.

<html><head>
 <title>Change url in browser bar</title>
</head>
     <body>
             <h1>Refresh page to see our other website</h1>
     </body>
 </html>
Run Code Online (Sandbox Code Playgroud)

当任何用户进入我的网站,如www.a-site.com打开此网站后,他会看到文本 刷新页面,以查看我们的其他网站.我能做到这一点,当他在进入www.a-site.com,就像在浏览器栏这个网址变更后www.b-site.com当用户刷新页面可以automaticaaly重定向
www.b-site.com.这是可能的吗?
谢谢...............

javascript url

2
推荐指数
1
解决办法
2万
查看次数

从Mysql表中删除重复行并仅保留一行

我想从Mysql表中删除所有重复的行.
但问题是我不知道哪些行是重复的.
这个Mysql表包含一个大约500000行的大数据.
其中一些行是重复的.
请指导我如何做到这一点.

更新:

我需要在phpMyAdmin中运行的SQL查询.
这是一个粗略的表格来理解.
假设表名是foo.

+---------------------------------------------------------------------+
| id |   link  |     title              |  description                |
+---------------------------------------------------------------------+
| 1  |  google |     search engine      |  search here free           |  
| 2  |  yahoo  |    also search engine  | findout web easily          |  
| 3  | Facebook|  connect with world    | meet with world             |  
| 4  | google  |  search engine         |  search here free           |
| 5  | msn     | Microsoft network      | network …
Run Code Online (Sandbox Code Playgroud)

mysql

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

javascript ×2

magic-methods ×2

php ×2

c++ ×1

file ×1

highlight ×1

html ×1

mysql ×1

oop ×1

replace ×1

search ×1

unset ×1

url ×1