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
189
votes
5 answers

PHP Difference between array() and []

I'm writing a PHP app and I want to make sure it will work with no errors. The original code: 'test', 'id' => 'theID'); echo form_input($data); ?> Would the following work with no errors or is not…
Mr.Web
  • 6,992
  • 8
  • 51
  • 86
150
votes
1 answer

Does a dot have to be escaped in a character class (square brackets) of a regular expression?

A dot . in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: \. It has been pointed out to me that inside square brackets [] a dot does not have to be escaped. For example, the…
Dariusz
  • 21,561
  • 9
  • 74
  • 114
122
votes
3 answers

When are square brackets required in a Bash if statement?

Usually, I use square brackets in the if statement: if [ "$name" = 'Bob' ]; then ... But, when I check if grep succeeded I don't use the square brackets: if grep -q "$text" $file ; then ... When are the square brackets necessary in the if…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
101
votes
8 answers

List of all Unicode's open/close brackets

What is a list of every Unicode bracket-like characters (including, for example: {}[]()<>)? What is a good way to search for Unicode characters?
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
74
votes
4 answers

Nested maps in Golang

func main() { var data = map[string]string{} data["a"] = "x" data["b"] = "x" data["c"] = "x" fmt.Println(data) } It runs. func main() { var data = map[string][]string{} data["a"] = append(data["a"], "x") data["b"] =…
Özgür Yalçın
  • 1,872
  • 3
  • 16
  • 26
72
votes
3 answers

What is the difference between curly brace and square bracket in Python?

what is the difference between curly brace and square bracket in python? A ={1,2} B =[1,2] when I print A and B on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use {} and [] to initialize different variables.…
Haoyu Chen
  • 1,760
  • 1
  • 22
  • 32
72
votes
2 answers

Overload bracket operators [] to get and set

I have the following class: class risc { // singleton protected: static unsigned long registers[8]; public: unsigned long operator [](int i) { return registers[i]; } }; as you can see I've…
SagiLow
  • 5,721
  • 9
  • 60
  • 115
60
votes
10 answers

Are square brackets permitted in URLs?

Are square brackets in URLs allowed? I noticed that Apache commons HttpClient (3.0.1) throws an IOException, wget and Firefox however accept square brackets. URL example: http://example.com/path/to/file[3].html My HTTP client encounters such URLs…
Benedikt Waldvogel
  • 12,406
  • 8
  • 49
  • 61
50
votes
2 answers

what is the purpose of using square brackets in json?

I am new to json. Some json examples i have seen have data within the curly braces and some json examples have subdata within square brackets. { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", …
Uswer721
  • 565
  • 1
  • 7
  • 13
43
votes
2 answers

Accessing arrays by index[array] in C and C++

There is this little trick question that some interviewers like to ask for whatever reason: int arr[] = {1, 2, 3}; 2[arr] = 5; // does this line compile? assert(arr[2] == 5); // does this assertion fail? From what I can understand, a[b] gets…
NullUserException
  • 83,810
  • 28
  • 209
  • 234
30
votes
3 answers

Removing [] around column in SQL Server 2005

when I was renaming the column in SQL Server, I accidentally inserted the square brackets around the column. The actual statement that I used was: SP_RENAME 'customer.[EMPLOYEENAMES]', '[EMPLOYEENAME]', 'COLUMN' But when I try to retrieve the data…
Sreedhar Danturthi
  • 7,119
  • 19
  • 68
  • 111
23
votes
10 answers

Copy file with square brackets [ ] in the filename and use * wildcard

I'm using PowerShell on Windows 7, and writing a script to copy a bunch of files from one folder structure to another. Kind of like compiling. The PowerShell Copy-Item cmdlet thinks that square brackets, [ ], are wildcards of some kind, and I am…
YetAnotherRandomUser
  • 1,320
  • 3
  • 13
  • 31
22
votes
1 answer

How can I mitigate injection/exfiltration attacks from dynamic property accesses (i.e. square bracket notation) in JavaScript?

After setting up eslint-plugin-security, I went on to attempt to address nearly 400 uses of square brackets in our JavaScript codebase (flagged by the rule security/detect-object-injection). Although this plugin could be a lot more intelligent, any…
Devin Rhode
  • 23,026
  • 8
  • 58
  • 72
20
votes
3 answers

Dynamically add query parameters without value to Retrofit request

I have request that set list of services that are turned on for user. Request has following format: https://myserver.com/setservices?param1=val1¶m2=val2&service[10]&service[1000]&service[10000] List of service parameters…
Yuriy
  • 1,466
  • 2
  • 14
  • 30
13
votes
7 answers

angular2 elvis operator and bracket notation / object access by key

So, let's say we got a simple object that holds a string for two different languages like welcomeText = {"de": "Willkommen zurück!", "en": "Welcome back!"}. The welcomeText is a property of Texts object that holds all texts and gets delivered…
ch40s
  • 580
  • 1
  • 7
  • 19
1
2 3
18 19