Tutorial by Examples: ast

If we know the length of the string, we can use a for loop to iterate over its characters: char * string = "hello world"; /* This 11 chars long, excluding the 0-terminator. */ size_t i = 0; for (; i < 11; i++) { printf("%c\n", string[i]); /* Print each character of ...
let strings = "bananas,apples,pear".split(","); split returns an iterator. for s in strings { println!("{}", s) } And can be "collected" in a Vec with the Iterator::collect method. let strings: Vec<&str> = "bananas,apples,pear"....
Constructor overloading is not available in As3. In order to provide a different way to retrieve an instance of a class, a public static method can be provided to serve as an alternative "constructor". An example for that is flash.geom.Point, which represents a 2D point object. The coor...
File streams are buffered by default, as are many other types of streams. This means that writes to the stream may not cause the underlying file to change immediately. In oder to force all buffered writes to take place immediately, you can flush the stream. You can do this either directly by invokin...
data.table offers a wide range of possibilities to reshape your data both efficiently and easily For instance, while reshaping from long to wide you can both pass several variables into the value.var and into the fun.aggregate parameters at the same time library(data.table) #v>=1.9.6 DT <- ...
If the compiler can infer that an object can't be null at a certain point, you don't have to use the special operators anymore: var string: String? = "Hello!" print(string.length) // Compile error if(string != null) { // The compiler now knows that string can't be null print(...
Use TO_CHAR( date [, format_model [, nls_params]] ): (Note: if a format model is not provided then the NLS_DATE_FORMAT session parameter will be used as the default format model; this can be different for every session so should not be relied on. It is good practice to always specify the format mod...
function listener(e:Event):void { var m:MovieClip=e.target as MovieClip; m.x++; } If such a listener is attached to an object that's not a MovieClip descendant (for example, a Sprite), the typecast will fail, and any subsequent operations with its result will throw the 1009 error.
If you have your data stored in a list and you want to convert this list to a data frame the do.call function is an easy way to achieve this. However, it is important that all list elements have the same length in order to prevent unintended recycling of values. dataList <- list(1:3,4:6,7:9) ...
Ever wanted to call a multicast delegate but you want the entire invokation list to be called even if an exception occurs in any in the chain. Then you are in luck, I have created an extension method that does just that, throwing an AggregateException only after execution of the entire list complete...
Visual Basic has Left, Right, and Mid functions that returns characters from the Left, Right, and Middle of a string. These methods does not exist in C#, but can be implemented with Substring(). They can be implemented as an extension methods like the following: public static class StringExtens...
explode and strstr are simpler methods to get substrings by separators. A string containing several parts of text that are separated by a common character can be split into parts with the explode function. $fruits = "apple,pear,grapefruit,cherry"; print_r(explode(",",$fruits))...
Encoding //Create a Base64 Encoded NSString Object NSData *nsdata = [@"iOS Developer Tips encoded in Base64" dataUsingEncoding:NSUTF8StringEncoding]; // Get NSString from NSData object in Base64 NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0]; // Print the B...
git diff HEAD^ HEAD This will show the changes between the previous commit and the current commit.
If you do not require an array to be in any particular order, a little trick with pop() will afford you enormous performance gains compared to splice(). When you splice() an array, the index of subsequent elements in that array needs to be reduced by 1. This process can consume a large chunk of tim...
The <algorithm> header provides a number of useful functions for working with sorted vectors. An important prerequisite for working with sorted vectors is that the stored values are comparable with <. An unsorted vector can be sorted by using the function std::sort(): std::vector<int&...
The Master directive specifies a page file as being the mater page. The basic syntax of sample MasterPage directive is: <%@ MasterPage Language="C#" AutoEventWireup="true" CodeFile="SiteMater.master.cs" Inherits="SiteMaster" %>
The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed. The basic syntax of MasterType directive is: <%@ MasterType attribute="value"[attribute="value" ...] %>
You can also use regular expressions to split a string. For example, import re data = re.split(r'\s+', 'James 94 Samantha 417 Scarlett 74') print( data ) # Output: ['James', '94', 'Samantha', '417', 'Scarlett', '74']
If you have a string that contains Python literals, such as strings, floats etc, you can use ast.literal_eval to evaluate its value instead of eval. This has the added feature of allowing only certain syntax. >>> import ast >>> code = """(1, 2, {'foo': 'bar'})&quot...

Page 7 of 26