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

python: why does replace not work?

倾然丶 夕夏残阳落幕 提交于 2020-05-24 04:47:10
问题 I wrote a quick script to remove the 'http://' substring from a list of website addresses saved on an excel column. The function replace though, doesn't work and I don't understand why. from openpyxl import load_workbook def rem(string): print string.startswith("http://") #it yields "True" string.replace("http://","") print string, type(string) #checking if it works (it doesn't though, the output is the same as the input) wb = load_workbook("prova.xlsx") ws = wb["Sheet"] for n in xrange(2,698

String.replace result is ignored?

▼魔方 西西 提交于 2020-05-23 21:26:41
问题 So i'm using IntelliJ and the replace buzzword is highlighted. Most of the tips are over my head so i ignore them, but what i got for this one was that the result of string.replace is ignored. Why? would i need something like ( string = string.replace(string.charAt(i)); )? import java.util.Scanner; public class PhoneNumberDecipher { public static String phoneNumber; public static String Decipher(String string) { string = phoneNumber; for(int i =0; i<=phoneNumber.length(); i++) { if(string

Remove an item from a comma-separated string [duplicate]

情到浓时终转凉″ 提交于 2020-05-23 12:38:07
问题 This question already has answers here : Fastest way of deleting a value in a comma separated list (4 answers) Closed 9 days ago . Let's say I have a string: cat,mouse,dog,horse Is there a regex or a function that will work as follows? 1)"cat" return string ->"mouse,dog,horse" 2)"mouse" return string ->"cat,dog,horse" 3)"dog" return string ->"cat,mouse,horse" 4)"horse" return string ->"cat,mouse,dog" I need to eliminate the selected item from the string and return the remaining parts of the

Remove an item from a comma-separated string [duplicate]

不想你离开。 提交于 2020-05-23 12:37:15
问题 This question already has answers here : Fastest way of deleting a value in a comma separated list (4 answers) Closed 9 days ago . Let's say I have a string: cat,mouse,dog,horse Is there a regex or a function that will work as follows? 1)"cat" return string ->"mouse,dog,horse" 2)"mouse" return string ->"cat,dog,horse" 3)"dog" return string ->"cat,mouse,horse" 4)"horse" return string ->"cat,mouse,dog" I need to eliminate the selected item from the string and return the remaining parts of the

How to increase a number in a string that also contains letters?

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-23 07:27:32
问题 I want to perform arithmetic operations on numbers in a string. For example: SGJKR67 should become SGJKR68 . Another one: NYSC34 should become NYSC35 . Only numbers are changed, in this example both are increased by one. 回答1: Using regex and Capturing Groups can solve your problem: $reg = [regex]::new("([A-Z]+)(\d+)") $m = $reg.Match("SGJKR67") $digits = $m.Groups[2] # will be 67 $digits = $digit + 1; # or apply anything you want $result = "$($m.Groups[1])$digits" # will be SGJKR and 68. You

How to recode existing text filter for regex search and replace?

天涯浪子 提交于 2020-05-17 18:44:10
问题 I was able to cobble the code below so that it performs multiple search and replace functions as a text filter. The code works in the EditPlus text editor program. I would like to execute the same idea except with regex search and replace. What is the correct way to code for multiple regex Search and Replaces in a text filter? enter code here Option Explicit Dim oWS, oFS Set oWS = WScript.CreateObject("WScript.Shell") Set oFS = WScript.CreateObject("Scripting.FileSystemObject") '---------- '

How to recode existing text filter for regex search and replace?

不问归期 提交于 2020-05-17 18:41:56
问题 I was able to cobble the code below so that it performs multiple search and replace functions as a text filter. The code works in the EditPlus text editor program. I would like to execute the same idea except with regex search and replace. What is the correct way to code for multiple regex Search and Replaces in a text filter? enter code here Option Explicit Dim oWS, oFS Set oWS = WScript.CreateObject("WScript.Shell") Set oFS = WScript.CreateObject("Scripting.FileSystemObject") '---------- '

Jquery Trim all spaces from variable

放肆的年华 提交于 2020-05-17 07:08:45
问题 On a click I store a variable. I would like to then trim that variable for all whitespace. I am getting an error when I to simply console.log the new variable. var songToTrim = $(this).html(); console.log(songToTrim); var songToPlay = songToTrim.replace(/ /g,''); console.log(songToPlay); For bonus points if you can add how to make sure the variable is converted to all lowercase that would be huge. If not it'll still work. Thanks! 回答1: Here is my solution Code: $("#test").on('click', function(

Golang idiomatic way to remove a blank line from a multi-line string

浪子不回头ぞ 提交于 2020-05-15 02:52:06
问题 If I have a multi line string like this is a line this is another line what is the best way to remove the empty line? I could make it work by splitting, iterating, and doing a condition check, but is there a better way? 回答1: Assumming that you want to have the same string with empty lines removed as an output, I would use regular expressions: import ( "fmt" "regexp" ) func main() { var s = `line 1 line 2 line 3` regex, err := regexp.Compile("\n\n") if err != nil { return } s = regex