Questions tagged [square-bracket]

The symbols "[" and "]", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

Overview

The square brackets "[" and "]" are special cases of brackets, along with parentheses and curly brackets (or braces) ("{", "}").

Uses

Square brackets have many uses in most programming languages, such as:

279 questions
12
votes
2 answers

Can't type certain square brackets in Visual Studio 2010 + Resharper

In certain cases typing an opening square bracket results in nothing at all. In particular when I want to type them on a variable in the right side of assignment expression: arr[i] = arr So I cant type, for example: arr[i] = arr[9] It has…
12
votes
2 answers

rules (?) of parens/brackets usage in perl

Did some search but couldn't find anything useful. I was wondering if there is a summary table of sort for beginners to learn about the "rules" of using parens/brackets, specifically, the differences among (), [], {}. Unfortunately, in my…
B Chen
  • 923
  • 2
  • 12
  • 21
11
votes
2 answers

Visual Studio Code bracket auto completion

This has been annoying me for a while. VSCode doesn't let me type a closing bracked or parenthesis or the like ( ")", "]", "}") when there is already a closing symbol of the same type. In this WEBM you see me try to set another set of brackets and…
kett
  • 877
  • 3
  • 9
  • 22
9
votes
6 answers

How to access 1D arrays with multiple brackets for readability?

I have a huge code using a 3D array managed with pointers. Something like: int *** tab; tab = malloc(m*sizeof(int**)); for(i= 1..n) tab[i] = malloc(n*sizeof(int*)); ... etc... and later the elements are accessed with: tab[i][j][k] = ... But…
Saiph
  • 510
  • 3
  • 16
8
votes
3 answers

Strange C++ syntax

I have 8 years of coding experience, but I have never seen the operator [] passed as a parameter to the function definition. For example, the following code (from an open source project): bree::porder(m_root, [] (treenode* node) { delete node;…
Arjun
  • 169
  • 1
8
votes
1 answer

Braces: [Brackets], (Parentheses) & {Curlies} in Ruby & Rails

So the loose tolerance of Ruby to use braces sometimes and not REQUIRE them has led to alot of confusion for me as I'm trying to learn Rails and when/where to use each and why? Sometimes parameters or values are passed as (@user, @comment) and other…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
8
votes
3 answers

python regex match optional square brackets

I have the following strings: 1 "R J BRUCE & OTHERS V B J & W L A EDWARDS And Ors CA CA19/02 27 February 2003", 2 "H v DIRECTOR OF PROCEEDINGS [2014] NZHC 1031 [16 May 2014]", 3 '''GREGORY LANCASTER AND JOHN HENRY HUNTER V CULLEN INVESTMENTS…
user740875
  • 89
  • 1
  • 1
  • 4
7
votes
5 answers

accessing array values without square brackets in php

In php how can I access an array's values without using square brackets around the key? My particular problem is that I want to access the elements of an array returned by a function. Say function(args) returns an array. Why is $var =…
amb
  • 489
  • 5
  • 9
7
votes
1 answer

Bracket notation on Ruby numbers

I found that when using bracket notation on the number 100 in Ruby, I get this: irb(main):001:0> 100[0] => 0 irb(main):002:0> 100[1] => 0 irb(main):003:0> 100[2] => 1 So I assumed it was getting the digits, indexed like this: NUMBER: 1|0|0 …
tckmn
  • 57,719
  • 27
  • 114
  • 156
7
votes
2 answers

Need RegExp help for Linux Bash grep command to filter out lines containing square brackets

Using the following example, I need to filter out the line containing 'ABC' only, while skipping the lines matching 'ABC' that contain square brackets: 2012-04-04 04:13:48,760~sample1~ABC[TLE 5332.233 2/13/2032 3320392]:CAST 2012-04-04…
6
votes
1 answer

How does function declaration by square brackets work in Node.js / Javascript?

First time seeing something like this in Node.js for declaring functions. In short, the code is similar to this 'use strict'; const Actions = { ONE: 'one', TWO: 'two', THREE: 'three' }; class FunMap { run(action) { const map = this; …
s-hunter
  • 24,172
  • 16
  • 88
  • 130
6
votes
2 answers

Hive: regexp_replace square brackets

I need to replace the square brackets around a key:value pair similar to the following. Any help is much appreciated! data in 'properties' looks like this: name: property1 value: [12345667:97764458] **code** SELECT p.name,…
Sarah Bergquist
  • 375
  • 2
  • 6
  • 10
5
votes
1 answer

Access grandchild of a variable (parent.child.grandchild) without dots and one pair of brackets

I'm building a canvas-related class with a kind of conversion table. The conversion table can be edited by the user. (Isn't really relevant, but maybe you want to know why): cLayout = function(option) { //obtaining the canvas (el) here …
bopjesvla
  • 755
  • 4
  • 15
  • 22
5
votes
2 answers

Square bracket notation and scope in JavaScript module pattern

I have been working with the module pattern in JavaScript and have a question about scope and square bracket notation (SBN). Please consider the following simple example. (function (module) { function myMethod(text) { …
Fraser
  • 15,275
  • 8
  • 53
  • 104
5
votes
1 answer

Double square brackets in Ruby

Given the following code: def map(char, charmap) unless map = charmap[[char]] unless map = charmap[[char, c = input.getc]] input.ungetc(c) if c map = '' end end map end What is the double square brackets…
pinker
  • 1,283
  • 2
  • 15
  • 32
1
2
3
18 19