Difference Between [Square Brackets] and *Asterisk

Difference between [square brackets] and *asterisk

When you use the type char x[] instead of char *x without initialization, you can consider them the same. You cannot declare a new type as char x[] without initialization, but you can accept them as parameters to functions. In which case they are the same as pointers.

When you use the type char x[] instead of char *x with initialization, they are completely 100% different.


Example of how char x[] is different from char *x:

char sz[] = "hello";
char *p = "hello";

sz is actually an array, not a pointer.

assert(sizeof(sz) == 6);
assert(sizeof(sz) != sizeof(char*));
assert(sizeof(p) == sizeof(char*));

Example of how char x[] is the same as char *x:

void test1(char *p)
{
assert(sizeof(p) == sizeof(char*));
}

void test2(char p[])
{
assert(sizeof(p) == sizeof(char*));
}

Coding style for passing to functions:

It really doesn't matter which one you do. Some people prefer char x[] because it is clear that you want an array passed in, and not the address of a single element.

Usually this is already clear though because you would have another parameter for the length of the array.


Further reading:

Please see this post entitled Arrays are not the same as pointers!

What is the difference between parentheses, brackets and asterisks in Angular2?

All details can be found here: https://angular.io/docs/ts/latest/guide/template-syntax.html

  • directiveName - is the short hand form for structural directives where the long form can only be applied to <template> tags. The short form implicitely wraps the element where it's applied in a <template>.

  • [prop]="value" is for object binding to properties (@Input() of an Angular component or directive or a property of a DOM element).

    There are special forms:

    • [class.className] binds to a css class to enable/disable it
    • [style.stylePropertyName] binds to a style property
    • [style.stylePropertyName.px] binds to a style property with a preset unit
    • [attr.attrName] binds a value to an attribute (visible in the DOM, while properties are not visible)
    • [role.roleName] binds to the ARIA role attribute (not yet available)
  • prop="{{value}}" binds a value to a property. The value is stringified (aka interpolation)

  • (event)="expr" binds an event handler to an @Output() or DOM event

  • #var or #var has different functions depending on the context

    • In an *ngFor="#x in y;#i=index" scope variables for the iteration are created
      (In beta.17 this is changed to *ngFor="let x in y; let i=index"`)
    • On a DOM element <div #mydiv> a reference to the element
    • On an Angular component a reference to the component
    • On an element that is an Angular component or has an Angular directive where exportAs:"ngForm" is defined, #myVar="ngForm" creates a reference to this component or directive.

Regular Expression square brackets with asterisk

Use a + quantifier to match 1 or more occurrences:

[^0-9a-zA-Z\s.]+
^

See the regex demo

Or, as Sebastian Proske comments, to make matching more precise, you may use a limiting quantifier {2,} to match 2 or more, or {3,} to match 3 or more, etc. (see the cheatsheet at the bottom).

var re = /[^0-9a-zA-Z\s.]+/; 

var str = 'The quick brown fox jumped over the lazy dog. The FCC had to censor the network for saying &$#*@!. There were 614 instances of students getting 90.0% or above.';

if (m=str.match(re)) {

console.log(m[0]);

}

C++ asterisk and bracket operators used together

Type declarations have an expression-like syntax, so you parse them as
you would an expression:

      x       x is
*x a pointer
(*x)[] to an array of unknown dimensions
int (*x)[] of int

The precedence rule is that the operators to the right bind tighter than
those to the left, in each case, the operator closer to the element
binds tighter, and finally, that parentheses can be used to change these
bindings, so:

int  *x[];    is an array of pointers,
int *(x[]); as is this.
int (*x)[]; whereas here, the parentheses change the bindings.

Regex for matching square brackets and number

Based on your shown samples, could you please try following.

import re
value='Example.[1]'
re.sub(r"\.\[\d+\]",'',value)

Explanation: Importing re library of python here. Then creating a sample variable named value which has Example.[1] in it. Now as per OP substituting .(DOT) [ followed by 1 or more occurrences of digits ] with NULL in value.

Regex to match asterisks, tildes, dashes and square brackets

You may use this regex with more alternations to include your desired matches:

const re = /\[[^\[\]\n]*\]|\b\w+\]|\[\w+|\*\*.+?(?:\*\*|$)|-+|(?:^|~~).+?~~|[\w ]+/mg;

const arr = [

'The special~~ quick brown fox jumps [over the] lazy **dog on** a **Sunday night.',

'The] quick brown fox jumps [over] the lazy [dog',

'The] quick [brown] fox **jumps** over ~~the~~ lazy dog --- in the [woods'

];

var n;

arr.forEach( str => {

m = str.match(re);

console.log(m);

});

What is Add-Type vs square bracket?

Add-Type is only used to load .NET types into a session (or to define them by ad hoc compilation).

To use these types by calling their constructors, you have two options:

  • In any PowerShell version:

    • Call the New-Object cmdlet.
  • Preferably, in PowerShell v5+:

    • Use a type literal ([...]) and call the type's (PowerShell-supplied) static ::new() method.
    • See this answer for more information about PowerShell type literals.

As Lee_Dailey and Theo note, using the static ::new() method has several advantages:

  • Calling ::new() is faster; with a single or only a few constructor calls that probably won't matter, but it may in loops.

  • Executing just ::new without parentheses shows all constructor overloads, which is a convenient way to find out what constructor arguments are needed and what their types are.

  • Calling ::new() doesn't wrap the newly created instance in a - mostly - invisible [psobject] wrapper, the way that New-Object and cmdlets in general do; while this wrapper is mostly benign, it can cause subtle differences in behavior - see GitHub issue #5579.

Note that, due to PowerShell's two fundamental parsing modes, New-Object and ::new() require different syntax, as discussed in this answer.

The angular brackets [] () {} what they bind and when to use which

All the above syntax can be found at this page of the Angular Documentation. You can read up more about Angular's Template Syntax on other blogs if you wish.

1) [class]="myclass"

The square brackets [...] represent the one-way property binding from the component logic (data) to the view (target element).

2) (ngModelChange)

This represents event binding, which allows the target to listen for certain events such as clicks and keypresses.

3) [(ngModel)]="mymodel2"

This represents two-way data binding, which combines the above two syntaxes. The property's data is displayed on the view, and at the same time, the property will be updated when the user makes any changes.

4) <ion-input placeholder="{{'INPUT_TEXT' | translate}}"/>

You are simply importing another component into your current component, and the placeholder attribute is assigned the value of the component property INPUT_TEXT through template interpolation.

The pipe operator (|) allows you to carry out transformation of the displayed value. Pipes accept an input and, return the respective transformed value

5) Similar to 4.

Print strings if there is not only single asterisk sign regexp

This piece uses reverse grep search.

data.file contains:

    check.test1[*,131]
check.test2[a,bc,,*,777]
check.test2[* ]
check.test[*]

Just run:

    grep -v '\[\*\]' /path/to/data.file

With output:

    check.test1[*,131]
check.test2[a,bc,,*,777]
check.test2[* ]


Related Topics



Leave a reply



Submit