parentheses

Remove Text Between Parentheses PHP

瘦欲@ 提交于 2019-11-26 02:35:18
问题 I\'m just wondering how I could remove the text between a set of parentheses and the parentheses themselves in php. Example : ABC (Test1) I would like it to delete (Test1) and only leave ABC Thanks 回答1: $string = "ABC (Test1)"; echo preg_replace("/\([^)]+\)/","",$string); // 'ABC ' preg_replace is a perl-based regular expression replace routine. What this script does is matches all occurrences of a opening parenthesis, followed by any number of characters not a closing parenthesis, and again

Ruby block and unparenthesized arguments

不羁岁月 提交于 2019-11-26 01:54:42
问题 I extracted simple example: require \'pp\' x = 1..3 pp x.map do |i| {:value => i, :double => (i*2)} end pp x.map { |i| {:value => i, :double => (i*2)} } pp(x.map do |i| {:value => i, :double => (i*2)} end) pp(x.map { |i| {:value => i, :double => (i*2)} }) I am wondering why first pp produces: [1, 2, 3] While all the oders are giving: [{:value=>1, :double=>2}, {:value=>2, :double=>4}, {:value=>3, :double=>6}] I assume it has something to do with operator precedence. Where can I find good

C macros and use of arguments in parentheses

做~自己de王妃 提交于 2019-11-26 01:43:33
问题 Example #define Echo(a) a #define Echo(a) (a) I realize there probably isn’t a significant difference here, but why would you ever want to include the a within parenthesis inside the macro body? How does it alter it? 回答1: Suppose you have #define mul(x, y) x * y What happens if I say: mul(a + 5, 6); /* a + 5 * 6 */ Now if I slighlty change the macro: #define mul(x, y) ((x) * (y)) mul(a + 5, 6); /* ((a + 5) * (6)) */ Remember, the arguments aren't evaluated or anything, only textual

The need for parentheses in macros in C [duplicate]

你。 提交于 2019-11-25 22:23:16
问题 This question already has an answer here: C macros and use of arguments in parentheses 2 answers I tried to play with the definition of the macro SQR in the following code: #define SQR(x) (x*x) int main() { int a, b=3; a = SQR(b+5); // Ideally should be replaced with (3+5*5+3), though not sure. printf(\"%d\\n\",a); return 0; } It prints 23 . If I change the macro definition to SQR(x) ((x)*(x)) then the output is as expected, 64 . I know that a call to a macro in C replaces the call with the