string

How to search for a string in all fields of every table in a MySQL database alvin May 30, 2017 - 11:04am

Here’s a cool tip: if you want to search for a text string in all fields of all tables of a MySQL database, you can use phpMyAdmin to do this very easily. Here are the steps to search every MySQL database table.

1) Select the desired database

The first step is to select the database you want to search. Don’t select a table — just select the database you want to search. (If you select a table you’ll get a different search form in Step 2.)

A ‘printf’ format reference page (cheat sheet)

Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my own purposes, and then thought I would share it here.

A cool thing about the printf formatting syntax is that the specifiers you can use are very similar, if not identical, between several different languages, including C, C++, Java, Perl, Ruby, and others, so your knowledge is reusable, which is a good thing.

How to get cleaned HTML as a String from HTMLCleaner alvin March 11, 2017 - 2:35pm

If you ever need to get the “cleaned” HTML as a String from the Java HTMLCleaner project, I hope this example will help:

How to print an array in Android Log output (Logcat) alvin February 7, 2017 - 7:55pm

If you need to dump the contents of an array to the Android Log (Logcat) output, I can confirm that this approach works, at least with simple arrays of integers and strings that know how to print themselves:

Log.i("MyAndroidClass", Arrays.toString(arr));

If you’re trying to print more complicated arrays of custom objects you’ll probably need to implement good toString methods on those objects, and then this technique should work.

Scala code to read a text file to an Array (or Seq) alvin January 17, 2017 - 5:04pm

As a quick note, I use code like this read a text file into an Array, List, or Seq using Scala:

def readFile(filename: String): Seq[String] = {
    val bufferedSource = io.Source.fromFile(filename)
    val lines = (for (line <- bufferedSource.getLines()) yield line).toList
    bufferedSource.close
    lines
}
Creating random strings and shuffling them (for JavaFX ListView) alvin January 17, 2017 - 4:35pm

As a short “note to self,” I just used this Scala code to (a) create a list that contains random strings of different lengths, then (b) shuffle the list of strings to create a more random effect:

You may not need to use StringBuilder in Java any more alvin December 23, 2016 - 12:13pm

Here’s a short article on dzone.com that explains why you might not need to use StringBuilder in Java any more.

Java BufferedReader, readLine, and a Scala while loop alvin September 14, 2016 - 8:52pm

I generally try to avoid this coding style these days, but, if you want to see how to use a Java BufferedReader and its readLine method in a Scala while loop, here you go:

How to use multiple regex patterns with replaceAll (Java String class) alvin September 8, 2016 - 12:14pm
Table of Contents1 - 1) A simple string2 - 2) Replace multiple patterns in that string3 - 3) More explanation4 - Multiple search patterns5 - Summary

Java FAQ: How can I use multiple regular expression patterns with the replaceAll method in the Java String class?

Here’s a little example that shows how to replace many regular expression patterns with one replacement string in Scala and Java. I’ll show all of this code in Scala’s interactive interpreter environment, but in this case Scala is very similar to Java, so the initial solution can easily be converted to Java.

A Java method to replace all instances of a pattern in a String with a replacement pattern alvin September 8, 2016 - 11:36am

Note: The code shown below is a bit old. If you want to perform a “search and replace” operation on all instances of a given pattern, all you have to do these days is use the replaceAll method on a Java String, like this:

String s = "123 Main Street";
String result = s.replaceAll("[0-9]", "-");

That second line of code returns the string “--- Main Street”. I kept the information below here for background information.