Tutorial by Examples: ast

In this example, we illustrate string manipulation in MATLAB MEX. We will create a MEX-function that accepts a string as input from MATLAB, copy the data into C-string, modify it and convert it back to mxArray returned to the MATLAB side. The main objective of this example is to show how strings ca...
Ruby provides several ways to create a String object. The most common way is using single or double quotes to create a "string literal": s1 = 'Hello' s2 = "Hello" The main difference is that double-quoted string literals are a little bit more flexible as they support interpo...
You may need to convert a Stream emitting Optional to a Stream of values, emitting only values from existing Optional. (ie: without null value and not dealing with Optional.empty()). Optional<String> op1 = Optional.empty(); Optional<String> op2 = Optional.of("Hello World");...
interface IFoo { } class Foo : IFoo { } class Bar : IFoo { } var item0 = new Foo(); var item1 = new Foo(); var item2 = new Bar(); var item3 = new Bar(); var collection = new IFoo[] { item0, item1, item2, item3 }; Using OfType var foos = collection.OfType<Foo>(); // result: IEnum...
String#split splits a String into an Array, based on a delimiter. "alpha,beta".split(",") # => ["alpha", "beta"] An empty String results into an empty Array: "".split(",") # => [] A non-matching delimiter results in an Array...
Given a String: s = "something" there are several ways to convert it to a Symbol: s.to_sym # => :something :"#{s}" # => :something
All java Collection<E>s have stream() and parallelStream() methods from which a Stream<E> can be constructed: Collection<String> stringList = new ArrayList<>(); Stream<String> stringStream = stringList.parallelStream(); A Stream<E> can be created from an arra...
In this example, we will look at a method for returning the last non-empty row in a column for a data set. This method will work regardless of empty regions within the data set. However caution should be used if merged cells are involved, as the End method will be "stopped" against a mer...
NSAttributedString (and its mutable sibling NSMutableAttributedString) allows you to create strings that are complex in their appearance to the user. A common application is to use this to display a string and adding custom kerning / letter-spacing. This would be achieved as follows (where label ...
While static constructors are always called before the first usage of a type it's sometimes useful to be able to force them to be called and the RuntimeHelpers class provide an helper for it: using System.Runtime.CompilerServices; // ... RuntimeHelpers.RunClassConstructor(typeof(Foo).TypeHand...
The String.Join method will help us to construct a string From array/list of characters or string. This method accepts two parameters. The first one is the delimiter or the separator which will help you to separate each element in the array. And the second parameter is the Array itself. String from...
PHP implements a DOM Level 2 compliant parser, allowing you to work with HTML using familiar methods like getElementById() or appendChild(). $html = '<html><body><span id="text">Hello, World!</span></body></html>'; $doc = new DOMDocument(); libxml_u...
Problem: Create a String containing n repetitions of a String s. The trivial approach would be repeatedly concatenating the String final int n = ... final String s = ... String result = ""; for (int i = 0; i < n; i++) { result += s; } This creates n new string instances ...
Example: Get a Stream of 30 elements, containing 21st to 50th (inclusive) element of a collection. final long n = 20L; // the number of elements to skip final long maxSize = 30L; // the number of elements the stream should be limited to final Stream<T> slice = collection.stream().skip(n).li...
3.0 In Swift 3 there are multiple access-levels. This example uses them all except for open: public struct Car { public let make: String let model: String //Optional keyword: will automatically be "internal" private let fullName: String fileprivate var otherName...
You can use the Integer method to convert a String to an Integer: Integer("123") # => 123 Integer("0xFF") # => 255 Integer("0b100") # => 4 Integer("0555") # => 365 You can also pass a base parameter to the Integer method to c...
A method of a struct that change the value of the struct itself must be prefixed with the mutating keyword struct Counter { private var value = 0 mutating func next() { value += 1 } } When you can use mutating methods The mutating methods are only available on str...
Structure data types are useful way to package related data and have them behave like a single variable. Declaring a simple struct that holds two int members: struct point { int x; int y; }; x and y are called the members (or fields) of point struct. Defining and using structs: ...
Fixnum#to_s takes an optional base argument and represents the given number in that base: 2.to_s(2) # => "10" 3.to_s(2) # => "11" 3.to_s(3) # => "10" 10.to_s(16) # => "a" If no argument is provided, then it represents the number in bas...
PHP will generally correctly guess the data type you intend to use from the context it's used in, however sometimes it is useful to manually force a type. This can be accomplished by prefixing the declaration with the name of the required type in parenthesis: $bool = true; var_dump($bool); // bool...

Page 4 of 26