Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

3 total

Export french characters

// description of your code here

java -Dfile.encoding=CP850 YourClassName
export JAVA_OPTS=-Dfile.encoding=UTF-8

String Samples

String samples
  
     System.setProperty("file.encoding","UTF-8") 
     System.setProperty("file.encoding","CP850")
     def delimiters = [:]

     //String data = new String((byte[])"é():;éééçç,.<>[]","UTF-8");

     def data =   "é():;éùùçç,.<>[]" 
     
     data = data.replace('é', 'e');
     println data
     println data.size()
     
     data.each { c ->
        // def str = Long.toHexString(c as long)
       def str = c
       //  if (!(c =~ /\w/)) {
         if (c == 'é') {
        	delimiters[c] = "Annul\u00E7e"
         }
         else if(c == 'ù') {
        	 delimiters[c] = "\u00E7"
         }         
         else
         {
        	 delimiters[c] = str
         }
     }
     println delimiters

test

// description of your code here

"def" is a replacement for a type name. In variable definitions it is used to indicate that you don't care about the type. In variable definitions it is mandatory to either provide a type name explicitly or to use "def" in replacement. This is needed to the make variable definitions detectable for the Groovy parser.

These definitions may occur for local variables in a script or for local variables and properties/fields in a class.
Rule of thumb
You can think of "def" as an alias of "Object" and you will understand it in an instant.

Future Groovy may give "def" an additional meaning in terms of static and dynamic typing. But this is post Groovy 1.0.
"def" can also replace "void" as the return type in a method definiton.

def dynamic  =  1
dynamic = "I am a String stored in a variable of dynamic type"
int typed = 2
typed = "I am a String stored in a variable of type int??"    // throws ClassCastException


The assignment of a string, to a variable of type int will fail. A variable typed with "def" allows this.

3 total