"함수 stringReplace()"의 두 판 사이의 차이

127번째 줄: 127번째 줄:
*[[함수 strtr()]]
*[[함수 strtr()]]
*[[함수 strpos()]]
*[[함수 strpos()]]
*[[함수 replace_nth()]]
*[[함수 str_replace_nth()]]
*[[stringByReplacingMatchesInString]]
*[[stringByReplacingMatchesInString]]
*[[str_replace_file]]
*[[str_replace_file]]
*[[str_repeat]]
*[[str_repeat]]
*[[replaces_between]]
*[[replaces_between]]

2016년 4월 10일 (일) 16:08 판

gsub
replace
sed
str_replace

1 Bash

STR="hello world"
OUTPUT=`echo $STR | sed 's/hello/yellow/'`
echo $OUTPUT
# yellow world
STR="hello world"
OUTPUT=`echo $STR | sed 's/hello/yellow/g'`
echo $OUTPUT
# yellow world

2 C#

"effffff".Replace("f", "jump");     // returns "ejumpjumpjumpjumpjumpjump"
"blah".Replace("z", "y");           // returns "blah"

3 Excel

=SUBSTITUTE("hello world", "hello", "yellow")
// yellow world

4 Java

"effffff".replace("f", "jump");     // returns "ejumpjumpjumpjumpjumpjump"
"effffff".replaceAll("f*", "jump"); // returns "ejump"

5 JavaScript

"effffff".replace('f','jump');  // returns "ejumpfffff"
"effffff".replace(/f/g,'jump');  // returns "ejumpjumpjumpjumpjumpjump"

6 Objective-C

[@"effffff" stringByReplacingOccurrencesOfString:@"f" withString:@"jump"]     // returns "ejumpjumpjumpjumpjumpjump"

7 Perl

$b = "effffff";
$b =~ s/f/jump/g;
# $b is "ejumpjumpjumpjumpjumpjump"

8 PHP

$b = str_replace("f", "jump", "effffff");
// returns "ejumpjumpjumpjumpjumpjump"

9 PowerShell

"effffff" -replace "f", "jump"      #  returns "ejumpjumpjumpjumpjumpjump"
"effffff" -replace "f*", "jump"     #  returns "ejump"

10 Python

"effffff".replace("f", "jump")
# returns "ejumpjumpjumpjumpjumpjump"

11 Ruby

puts "effffff".gsub("f", "jump")
# ejumpjumpjumpjumpjumpjump
puts "effffff".gsub(/f/, "jump")
# ejumpjumpjumpjumpjumpjump
str = "effffff"
str2 = str.gsub("f", "jump") 
puts str2
str = "effffff"
str.gsub!("f", "jump") 
puts str

12 SQL

12.1 MS-SQL

12.2 MySQL

SELECT REPLACE("hello world", "hello", "yellow");
-- yellow world

13 VB

Replace("effffff", "f", "jump")     '  returns "ejumpjumpjumpjumpjumpjump"
Replace("blah", "z", "y")           '  returns "blah"

14 같이 보기