You can use the Substring method to get any number of characters from a string at any given location. However, if you only want a single character, you can use the string indexer to get a single character at any given index like you do with an array:
string s = "hello";
char c = s[1]; //...
When you need to pass a collection into a Java method:
import scala.collection.JavaConverters._
val scalaList = List(1, 2, 3)
JavaLibrary.process(scalaList.asJava)
If the Java code returns a Java collection, you can turn it into a Scala collection in a similar manner:
import scala.collectio...
To create minification-safe angular controllers, you will change the controller function parameters.
The second argument in the module.controller function should be passed an array, where the last parameter is the controller function, and every parameter before that is the name of each injected val...
defmodule Math do
# We start of by passing the sum/1 function a list of numbers.
def sum(numbers) do
do_sum(numbers, 0)
end
# Recurse over the list when it contains at least one element.
# We break the list up into two parts:
# head: the first element of the list
# ta...
.gitignore ignores files locally, but it is intended to be committed to the repository and shared with other contributors and users. You can set a global .gitignore, but then all your repositories would share those settings.
If you want to ignore certain files in a repository locally and not make t...
create table empl (
name text primary key,
boss text null
references name
on update cascade
on delete cascade
default null
);
insert into empl values ('Paul',null);
insert into empl values ('Luke','Paul');
insert into empl values ('Kate'...
Public Module Usage
Public Sub LikeThis()
Dim iCount As Integer
Dim sCount As String
iCount = 245
sCount = iCount.PadLeft(4, "0")
Console.WriteLine(sCount)
Console.ReadKey()
End Sub
End Module
Public Module Padding
<Extension>
Pub...
[^0-9a-zA-Z]
This will match all characters that are neither numbers nor letters (alphanumerical characters). If the underscore character _ is also to be negated, the expression can be shortened to:
[^\w]
Or:
\W
In the following sentences:
Hi, what's up?
I can't wait for 2017!...
[^0-9]
This will match all characters that are not ASCII digits.
If Unicode digits are also to be negated, the following expression can be used, depending on your flavor/language settings:
[^\d]
This can be shortened to:
\D
You may need to enable Unicode character properties support expl...
If you have an instance of a generic type but for some reason don't know the specific type, you might want to determine the generic arguments that were used to create this instance.
Let's say someone created an instance of List<T> like that and passes it to a method:
var myList = new List<...
Suppose we want to receive a function as a parameter, we can do it like this:
function foo(otherFunc: Function): void {
...
}
If we want to receive a constructor as a parameter:
function foo(constructorFunc: { new() }) {
new constructorFunc();
}
function foo(constructorWithParams...
The internal keyword is an access modifier for types and type members. Internal types or members are accessible only within files in the same assembly
usage:
public class BaseClass
{
// Only accessible within the same assembly
internal static int x = 0;
}
The difference between dif...
The steps of overload resolution are:
Find candidate functions via name lookup. Unqualified calls will perform both regular unqualified lookup as well as argument-dependent lookup (if applicable).
Filter the set of candidate functions to a set of viable functions. A viable function for whi...
In the timeline of any DisplayObject that is attached as a descendant of the display tree, you can utilise the root property. This property points to the main timeline in the case of no custom document class, or the document class if you do define one.
Because root is typed DisplayObject, the compi...
Enums are iterable:
class Color(Enum):
red = 1
green = 2
blue = 3
[c for c in Color] # [<Color.red: 1>, <Color.green: 2>, <Color.blue: 3>]
Add this permission to the manifest file to use Bluetooth features in your application:
<uses-permission android:name="android.permission.BLUETOOTH" />
If you need to initiate device discovery or manipulate Bluetooth settings, you also need to add this permission:
<uses-permi...
private static final int REQUEST_DISCOVERABLE_BT = 2; // Unique request code
private static final int DISCOVERABLE_DURATION = 120; // Discoverable duration time in seconds
// 0 means always discoverable
...
where can serve two purposes in C#: type constraining in a generic argument, and filtering LINQ queries.
In a generic class, let's consider
public class Cup<T>
{
// ...
}
T is called a type parameter. The class definition can impose constraints on the actual types that can be suppl...
A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting.
A simple usage example:
Import:
from sklearn.ensemble import RandomForestClassifier
Define tr...