标签: str-replace

在PHP中替换'"

关于str_replace的一个有趣的问题.

这是一个例子:

$search  = array('A', 'B', 'C', 'D', 'E');
$replace = array('B', 'C', 'D', 'E', 'F');
$subject = 'A';
echo str_replace($search, $replace, $subject);
Run Code Online (Sandbox Code Playgroud)

如果我想把"更换成别的东西,比如说 - 怎么办?"

问题是我不能写这样的东西

$search  = array(''"', 'B', 'C', 'D', 'E');
$replace = array('-', 'C', 'D', 'E', 'F');
$subject = 'A';
echo str_replace($search, $replace, $subject);
Run Code Online (Sandbox Code Playgroud)

有解决方案吗

php str-replace

0
推荐指数
1
解决办法
110
查看次数

str_replace()错误的参数计数错误

<?php
$kw = $_POST["kw"];
$kw= str_replace("*","%",$kw,$count);
if($count > 1) 
{
echo "not supported";
exit;
}
...
?>
Run Code Online (Sandbox Code Playgroud)

我收到此警告"str_replace()错误的参数计数错误".

我哪里错了?

谢谢.

php string str-replace

0
推荐指数
1
解决办法
2257
查看次数

String.Replace()擦除整个字符串-C#

我有一段代码,我正在修改文件的内容.我实际上需要用新行替换文件中的一行.为此,我这样做:

    private void btn_edit_Click(object sender, EventArgs e)
    {
        bufferedListView1.Items.Clear();
        StreamReader sr1 = new StreamReader("C:\\sample.txt");
        string file= sr1.ReadToEnd();
        if (file.Contains(pname + "@" + pno))
        {
            file.Replace(pname + "@" + pno, txt_editname.Text+"@"+txt_editno.Text);//Results null in file
        }
        string efile= sr1.ReadToEnd(); // returns null
        sr1.Close();
        StreamWriter sw1 = new StreamWriter("C:\\sample.txt");
        sw1.Write(efile);
        sw1.Close();
        //Rest of the code
Run Code Online (Sandbox Code Playgroud)

pname, pno contains old values. txt_editname,txt_editno contains new values

我最终在文件sample.txt没有内容.是什么原因?

c# file str-replace

0
推荐指数
1
解决办法
296
查看次数

Python从unicode列表中删除选项卡和托架行

我已经看过以前对此的答案(python如何从字符串或列表中删除此n,从列表删除列表项,python删除字符串中的空格)但无法使解决方案起作用.

我有一个包含单个元素的列表,如下所示:

list = [u'\r\n\r\n\r\n            \r\n                \r\n                    \r\n                    123 Main St., Peoria\r\n                \r\n\r\n            \r\n             |\r\n             \r\n                    \r\n                        \r\n                            \r\n                            123-456-789\r\n                        \r\n                    \r\n            \r\n        ']
Run Code Online (Sandbox Code Playgroud)

它有一个地址和一个电话号码,我想要的只是返回的是:

123 Main St., Peoria;123-456-789
Run Code Online (Sandbox Code Playgroud)

我试过像这样的东西:

str(list).strip(' \r\n\t')
Run Code Online (Sandbox Code Playgroud)

str(list).replace('\r','')
Run Code Online (Sandbox Code Playgroud)

但它们不起作用,所以我想也许这是一个unicode问题?我该如何解决这个问题?

python unicode str-replace

0
推荐指数
1
解决办法
6146
查看次数

如何指定括在方括号中的文本

我有一个字符串,其中包含多个用方括号括起来的文本,我需要将其删除,例如:

10/21/2012 12:12:15 [12:12:28]在大堂旋转门#4(IN)[In] [注意]中承认最后一次(卡#555)

我尝试了String.replaceAll,replaceFirst使用正则表达式"\ [.*\]"删除了第一个[和最后一个]之间的所有文本,我最终得到了

10/21/2012 12:12:15

我坚持如何指定表达式.任何帮助,将不胜感激.

java regex replaceall str-replace

0
推荐指数
1
解决办法
755
查看次数

替换列表中的字符串不起作用

在我的生活中,我不能理解为什么Replace();当我尝试替换String类型列表中的元素文本时该方法不起作用.这个问题在某种程度上与我之前的一个帖子有关[在这里找到:合并两个文件并处理重复的条目(对于完整的代码,查看它也是一个好主意)],但最后当天,这一切归结为命令不起作用,而我的代码实际上是正确的(!).

我会举例说明在我的情况下什么不起作用.在最基本的形式中,为了举例,这是我想要完成但它不起作用(真实!):

[在我的原始代码中,我已经三次检查(使用断点和所有内容)我的列表确实包含我要替换的字符串(我正在替换元素本身!),但它不会这样做!严肃地说,现在它是一个4元素列表(尽管可以添加更多元素,参考其他线程).

最后一件事,对标点符号感到遗憾(我知道的感叹号太多了),但我实际上对此持续不满.下面的代码(记住,最基本的形式,但我试过的一个例子):

// List[index].Replace(oldValue, newValue);
newFile[3].Replace(newFile[3], "Replace it with this!");
Run Code Online (Sandbox Code Playgroud)

你能帮帮我吗?

c# string replace list str-replace

0
推荐指数
1
解决办法
442
查看次数

如何删除java中的子字符串

我收到一个附加了"xyz"的文件路径.名称看起来像D:/sdcard/filename.docxyz

我使用以下代码删除xyz但它无法正常工作.这里缺少什么?

    String fileExtension = path.substring(path.lastIndexOf(".")+1);

    String newExtension= fileExtension;

    newExtension.replace("xyz", "");

    path.replace(fileExtension, newExtension);

    return path;
Run Code Online (Sandbox Code Playgroud)

java string android str-replace

0
推荐指数
2
解决办法
132
查看次数

str_replaceon®符号在PHP中不起作用

在标题中说的都是真的.以下代码始终返回false:

$product = str_replace('®', '', $product);    
Run Code Online (Sandbox Code Playgroud)

我也尝试过搜索®符号的html实体.

这有解决方案吗?

php string str-replace

0
推荐指数
1
解决办法
345
查看次数

如何减少我的str_replace php代码?

如何减少我的str_replace php代码?

我想删除aass直到zass

这是我的PHP代码,它的工作正常.但我想减少.我能怎么做 ?

<?PHP
$str = str_replace('aass', '', $str);
$str = str_replace('bass', '', $str);
$str = str_replace('cass', '', $str);
$str = str_replace('dass', '', $str);
$str = str_replace('eass', '', $str);
$str = str_replace('fass', '', $str);
$str = str_replace('gass', '', $str);
$str = str_replace('hass', '', $str);
$str = str_replace('iass', '', $str);
$str = str_replace('jass', '', $str);
$str = str_replace('kass', '', $str);
$str = str_replace('lass', '', $str);
$str = str_replace('mass', '', $str);
$str = str_replace('nass', '', $str);
$str = str_replace('oass', '', …
Run Code Online (Sandbox Code Playgroud)

php string str-replace

0
推荐指数
1
解决办法
101
查看次数

从字符串C++中删除元音

所以我是C++的新手,并尝试创建一个可以从字符串中删除元音的函数,但是我很失败,到目前为止这是我的代码:

#include <string>
using namespace std;
string remove(string st) {
    for(int i = 0; st[i] != '\0'; i++) 
        st[i] = st[i] == 'a' || st[i] == 'e' || st[i] == 'i' || st[i] == 'o' || st[i] ==
        'u' || st[i] == 'A' || st[i] == 'E' || st[i] == 'I' || st[i] == 'O' || st[i] ==
        'U' ? '' : st[i];
    }
return st;
Run Code Online (Sandbox Code Playgroud)

这似乎引发了一个错误?我知道我做错了什么

我得到的错误是:

main.cpp:10:16: error: expected expression 'U' ? '' : Z[i];
Run Code Online (Sandbox Code Playgroud)

并在另一个解释器上运行:

   .code.tio.cpp:7:14: error: …
Run Code Online (Sandbox Code Playgroud)

c++ regex string str-replace

0
推荐指数
1
解决办法
2641
查看次数

标签 统计

str-replace ×10

string ×6

php ×4

c# ×2

java ×2

regex ×2

android ×1

c++ ×1

file ×1

list ×1

python ×1

replace ×1

replaceall ×1

unicode ×1