str-replace

PHP remove number from comma seperated string stored in db [duplicate]

左心房为你撑大大i 提交于 2020-05-24 06:21:11
问题 This question already has answers here : Fastest way of deleting a value in a comma separated list (4 answers) Closed 10 days ago . I am storing numbers in a database with a string like 5,55,15,17,2,35 I want to remove say number 5 from the string, keeping the comma seperation set like it is. The problem with using str_replace() is that all of the 5's will be removed. If i use str_replace('5,'', $string) thats fine, but the comma wouldn't be after the 5 if it was in the middle of the string

How to replace column with strings with look-up codes in R

风格不统一 提交于 2020-04-07 05:25:49
问题 Imagine that I have a dataframe or datatable with strings column where one row looks like this: a1; b: b1, b2, b3; c: c1, c2, c3; d: d1, d2, d3, d4 and a look-up table with codes for mapping each of these strings. For example: string code a1 10 b1 20 b2 30 b3 40 c1 50 c2 60 ... I would like to have a mapping function that maps this string to code: 10; b: 20, 30, 40; c: 50, 60, 70; d: 80, 90, 100 I have a column of these strings in data.table/data.frame (more tha 100k) so any quick solution

str_replace_all replacing named vector elements iteratively not all at once

若如初见. 提交于 2020-02-24 05:53:26
问题 Let's say I have a long character string: pneumonoultramicroscopicsilicovolcanoconiosis. I'd like to use stringr::str_replace_all to replace certain letters with others. According to the documentation, str_replace_all can take a named vector and replaces the name with the value. That works fine for 1 replacement, but for multiple it seems to do it iteratively, so the result is a replacement of the prelast iteration. I'm not sure this is the intended behaviour. library(tidyverse) text_string =

Odd behavior for replacing newlines in PHP

旧巷老猫 提交于 2020-01-26 03:55:06
问题 I've encountered some strange behavior with PHP. I have a string of text from a <textarea/> input and it seems that: $text = str_replace(array("\r\n", "\r", "\n"), null, $text); successfully removes the newlines, whereas $text = str_replace("\n", " ", $text) $text = str_replace("\r\n", " ", $text) $text = str_replace("\r", " ", $text) EDIT: the three str_replace calls above are for \n, \r\n, and \r does NOT successfully remove newlines. I even tried adding: $text = str_replace(PHP_EOL, " ",

Replacing ampersand with the word and in URL's using existing str_replace

孤街醉人 提交于 2020-01-25 07:01:26
问题 I'm needing to replace ampersand ( & ) with the word and in URL's and am already replacing spaces with hyphens using php str_replace like below:- <?php echo strtolower(str_replace(' ', '-', $value)) ?> Am I able to modify this to add the replacement of ampersands as well by using an array perhaps? 回答1: To replace both strings in one statement, do the following; <?php $find = array(" ", "&"); $replace = array("-", "and"); $string = "Hello I am a man & I have a dog"; echo str_replace($find,

Removing Dollar and comma from string

不问归期 提交于 2020-01-20 03:24:04
问题 How can we remove dollar sign ($) and all comma(,) from same string? Would it be better to avoid regex? String liveprice = "$123,456.78"; 回答1: do like this NumberFormat format = NumberFormat.getCurrencyInstance(); Number number = format.parse("\$123,456.78"); System.out.println(number.toString()); output 123456.78 回答2: Try, String liveprice = "$123,456.78"; String newStr = liveprice.replaceAll("[$,]", ""); replaceAll uses regex, to avoid regex than try with consecutive replace method. String

Replace “//” with “/* */” in PHP? [closed]

我的未来我决定 提交于 2020-01-17 18:11:24
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce

Replace “//” with “/* */” in PHP? [closed]

送分小仙女□ 提交于 2020-01-17 18:09:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce

Replace “//” with “/* */” in PHP? [closed]

99封情书 提交于 2020-01-17 18:08:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce

dplyr string match and replace based on lookup table in R

杀马特。学长 韩版系。学妹 提交于 2020-01-16 18:27:30
问题 I'm trying to achieve a function that I previously did in Excel, but having trouble finding a means to achieve it. I have two datasets: one is my base dataset and the other is a lookup table. My base has two columns, the first and last names of people. My lookup table has these first two columns as well, but it also includes a replacement first name. People <- data.frame( Fname = c("Tom","Tom","Jerry","Ben","Rod","John","Perry","Rod"), Sname = c("Harper","Kingston","Ribery","Ghazali","Baker",