Tutorial by Examples

Using the System.String.Replace method, you can replace part of a string with another string. string s = "Hello World"; s = s.Replace("World", "Universe"); // s = "Hello Universe" All the occurrences of the search string are replaced. This method can al...
The System.String class supports a number of methods to convert between uppercase and lowercase characters in a string. System.String.ToLowerInvariant is used to return a String object converted to lowercase. System.String.ToUpperInvariant is used to return a String object converted to upper...
The System.String.Join method allows to concatenate all elements in a string array, using a specified separator between each element: string[] words = {"One", "Two", "Three", "Four"}; string singleString = String.Join(",", words); // singleString =...
String Concatenation can be done by using the System.String.Concat method, or (much easier) using the + operator: string first = "Hello "; string second = "World"; string concat = first + second; // concat = "Hello World" concat = String.Concat(first, second); // ...
Configure profiling for a project via stack. First build the project with the --profile flag: stack build --profile GHC flags are not required in the cabal file for this to work (like -prof). stack will automatically turn on profiling for both the library and executables in the project. The next...
To find out what packages your project directly depends on, you can simply use this command: stack list-dependencies This way you can find out what version of your dependencies where actually pulled down by stack. Haskell projects frequently find themselves pulling in a lot of libraries indirec...
Add the following code to the onCreate()/onResume() method: SensorManager sensorManager; Sensor mAccelerometer; final float movementThreshold = 0.5f; // You may have to change this value. boolean isMoving = false; float[] prevValues = {1.0f, 1.0f, 1.0f}; float[] currValues = new float[3]; ...
Consider the following code as an illustration: public String joinWords(List<String> words) { String message = ""; for (String word : words) { message = message + " " + word; } return message; } Unfortunate this code is inefficient if the w...
string path = @"c:\path\to\file.txt"; File.Delete(path); While Delete does not throw exception if file doesn't exist, it will throw exception e.g. if specified path is invalid or caller does not have the required permissions. You should always wrap calls to Delete inside try-catch bloc...
Get all files in Directory var FileSearchRes = Directory.GetFiles(@Path, "*.*", SearchOption.AllDirectories); Returns an array of FileInfo, representing all the files in the specified directory. Get Files with specific extension var FileSearchRes = Directory.GetFiles(@Path, "*...
6.0 Default SET format is MMDDhhmm[[CC]YY][.ss], that's (2 digits each) For example, to set July 17'th 10:10am, without changing the current year, type: adb shell 'date 07171010.00' Tip 1: the date change will not be reflected immediately, and a noticable change will happen only after the syst...
For most GNU/Linux distributions, a version of GnuCOBOL is available in the repositories. GnuCOBOL was originally OpenCOBOL, rebranded when the project became an official GNU project. Many repositories are still using open-cobol as the package name (as of August 2016). For Fedora, and other RPM b...
Put your dbname.sqlite or dbname.db file in assets folder of your project. public class Databasehelper extends SQLiteOpenHelper { public static final String TAG = Databasehelper.class.getSimpleName(); public static int flag; // Exact Name of you db file that you put in as...
By going to Settings >> Keymap A window will popup showing All the Editor Actions with the their name and shortcuts. Some of the Editor Actions do not have shortcuts. So right click on that and add a new shortcut to that. Check the image below
Problem: If after the AsyncTask starts there is a screen rotation the owning activity is destroyed and recreated. When the AsyncTask finishes it wants to update the UI that may not valid anymore. Solution: Using Loaders, one can easily overcome the activity destruction/recreation. Example: ...
When a Google Map is displayed in lite mode clicking on a map will open the Google Maps application. To disable this functionality you must call setClickable(false) on the MapView, e.g.: final MapView mapView = (MapView)view.findViewById(R.id.map); mapView.setClickable(false);
com.android.dex.DexException: Multiple dex files define Lcom/example/lib/Class; This error occurs because the app, when packaging, finds two .dex files that define the same set of methods. Usually this happens because the app has accidentally acquired 2 separate dependencies on the same library....
public class PlaySound extends Activity implements OnTouchListener { private SoundPool soundPool; private int soundID; boolean loaded = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { su...
Having more than one element with the same ID is a hard to troubleshoot problem. The HTML parser will usually try to render the page in any case. Usually no error occurs. But the pace could end up in a mis-behaving web page. In this example: <div id="aDiv">a</div> <div id...
To ignore a test, simply add the @Ignore annotation to the test and optionally provide a parameter to the annotation with the reason. @Ignore("Calculator add not implemented yet.") @Test public void testPlus() { assertEquals(5, calculator.add(2,3)); } Compared to commenting the...

Page 644 of 1336