This
sed "s/public \(.*\) get\(.*\)()/\1 \2/g"
will transfor this
public class ChallengeTO extends AbstractTransferObject {
public AuthAlgorithm getAlgorithm();
public long getCode();
public int getIteration();
public String getPublicKey();
public String getSelt();
};
into this
public class ChallengeTO extends AbstractTransferObject {
AuthAlgorithm Algorithm;
long Code;
int Iteration;
String PublicKey;
String Selt;
};
I want to change Algorithm to algorithm, PublicKey to publicKey and so on. How can I transform the first character of the second segment (\2) to lower case?
UPDATE
sed "s/public \(.*\) get\([A-Z]\)\(.*\)()/\1 \2\3/g" selects "my letter" as \2, but if I place a \L before it it transforms too much (including \3)
here's an awk solution
awk '
$1=="public" && $3~/^get/ {
sub(/^get/,"",$3)
$3=tolower( substr($3,1,1) ) substr($3,2)
$0="\t"$2" "$3
}1' file
output
$ cat file
public class ChallengeTO extends AbstractTransferObject {
public AuthAlgorithm getAlgorithm();
public long getCode();
public int getIteration();
public String getPublicKey();
public String getSelt();
};
$ ./shell.sh
public class ChallengeTO extends AbstractTransferObject {
AuthAlgorithm algorithm();
long code();
int iteration();
String publicKey();
String selt();
};
if you still prefer sed, here's a modification to your version, adding \l
$ sed 's/public \(.*\) get\([A-Z]\)\(.*\)()/\1 \l\2\3/g' file
public class ChallengeTO extends AbstractTransferObject {
AuthAlgorithm algorithm;
long code;
int iteration;
String publicKey;
String selt;
};
This is nearly identical to upper- to lower-case using sed.
EDIT: The question/answer there uses the \L GNU sed extension. The conversion begun by \L can be turned off by \E, so if you tease out "your letter" into \2, you can put a \L before it and a \E immediately after it.
See the GNU sed documentation for more information.
If you don't have GNU extensions, you can do this with two separate sed commands. You can use the y command to change a character that matches one of a source character into a corresponding destination character. This is similar to the Unix utility tr.
Related
public class MyFirstApp {
public static void main(String[] args) {
System.out.println(“I Rule!”);
System.out.println(“The World”);
}
}
When try to compile It in cmd using javac MyFirstApp.java it says that there is an unmappable character (0x9D) for encoding. What Is the problem?
The quotation marks in:
System.out.println(“I Rule!”);
System.out.println(“The World”);
are not correct. They are different for left & right. They should be plain ordinary "
System.out.println("I Rule!");
System.out.println("The World");
This type of problem is often caused by using a word processor (e.g., Word) rather than a text editor or "programmer's editor" (simplest typical example is Notepad, but there are plenty of free and low-cost alternatives that are much more powerful).
I am new to drools decision table, so my question may be invalid.
In my decision table i am using "in" in condition column.
Exampe : i have class Student and there is another class UniversityConstant.
In UniversityConstant class there is array of string subject code : public static final String[] subjectCode ={"150","920","930","940","154"};
In this case my condition not working properly(Above picture: Not working). Instead of using string array constant of java class if i use direct subject code string than it is working(Below picture:working).
In my project there are lots of string array ,so it is not possible to copy paste them in decision table excel. Even in case i use string constant in UniversityConstant class which represent all subject code like public static final String subjectCodeStr1 ="\"155\",\"920\",\"930\",\"940\",\"154\"" OR
public static final String subjectCodeStr2 ="155,920,930,940,154"; than also it is not working. My question is there any way to use string array constant or simple string which represents array of string of java
in decision table .
You can declare the constant sets as
public static final List<String> subjectCodes =
Arrays.asList( "155","920","930","940","154" );
and use
...getPrimarySub() memberOf $param
...
UniversityConstamt.subjectCodes
I am creating a game in Unity3d.
Somewhere I have hints appearing in the bottom of the HUD (Something like "press A for Action"). I want my game to support more languages and I don't want these hints to be hard-coded in the script.
What is the most elegant way to solve this task? I am thinking about txt file, where I will have all my hints in all languages. But I am not sure, if it is a good idea.
Thanks in advance.
A common way that is used is to have an XML-file for each language. The XML-file should contain every phrase you use in your game with a unique ID.
In your code, you can then get the correct phrase out of the current language's XML, using the correct ID.
If you don't know about XML files, read this tutorial about using XML files in Unity: http://xeophin.net/en/blog/2010/05/13/reading-strings-out-xml-file-using-c-unity-3d
However if you are willing to spend some money on your game, you should check this out: http://u3d.as/content/rodrigo-barros/my-menu/32E
I haven't tried that yet but it seems good.
Hardcoding is not that bad if you do it correctly.
For example create an abstract class with all the messages that you want to have and language autodetection:
public abstract class Lang {
static Lang currentLang;
public static Lang Get {
get {
if(currentLang == null)
switch(Application.systemLanguage) {
case SystemLanguage.Polish:
currentLang=new LangPL();
break;
default:
case SystemLanguage.English:
currentLang=new LangEN();
break;
}
return currentLang;
}
}
public abstract string MenuTime {get;}
public abstract string MenuPoints {get;}
public abstract string YouWon {get;}
public abstract string YouLost {get;}
public abstract string Point(int p);
}
And then implement each language as a separate class:
public class LangPL:Lang {
public override string MenuTime {get {return "CZAS";}}
public override string MenuPoints {get {return "WYNIK";}}
public override string YouWon {get {return "Gratuluję, wygrałeś!";}}
public override string YouLost{get {return "Może następnym razem...";}}
public override string Point(int p) {
if(p == 1)
return "1 punkt";
return p+" punktów";
}
}
public class LangEN:Lang {
public override string MenuTime {get {return "TIME";}}
public override string MenuPoints {get {return "SCORE";}}
public override string YouWon {get {return "You won!";}}
public override string YouLost{get {return "Maybe next time...";}}
public override string Point(int p) {
if(p == 1)
return "1 point";
return p+" points";
}
}
Usage is a simple:
GUILayout.Label(Lang.Get.YouWon);
GUILayout.Label(Lang.Get.Point(5));
This way you have most control, and can easily support complex translations. Also this approach helps to trim down on errors - if you forget or misstype a text anywhere it throws a syntax error.
You can try to create a Javascript script or a C# script for each language and then depending of the language choosen, you call the specific script.
e.g
public class English : MonoBehaviour{
public string jump = "Press 'space' to jump";
//etc
}
public class French : MonoBehaviour{
public string jump = "Appuyer sur 'espace' pour sauter";
//etc
}
In your function for GUIText
public GameController gameController;
public GUIText text;
private string languageSelected;// obtain from the user input on language selection (better if registered in the gameController)
void Awake(){
languageSelected = System.Activator.CreateInstance(Type.GetType(gameController.languageSelected));
// where languageSelected will be e.g English
text.text = languageSelected.jump;
}
I strongly advise against embedding text into your code. It will slow down the localization process (having to look through code to find text is not the quickest and best way to approach localization).
Go with separate files. It's easier to maintain and translators don't have to access the code.
Have a look at l2 localization. It's a pretty handy Unity plugin that allows you to manage translations of your game.
All your localized strings in a single Google Spreadsheet. Once set up, all you need to do is fill it out to see the results in the game.
I am a game translator myself and happen to be managing a small team of game translators called Level Up Translation. We posted a beginner's guide for localization in Unity in our blog a couple of months ago. Feel free to check it out!
For example, you can save language file for france.txt in format:
hello=Bonjour
goodbye=Au Revoir
And than, read file and convert it to dictionary:
string[] lines = File.ReadAllLines("france.txt");
var dict = lines.Select(l => l.Split('=')).ToDictionary(a => a[0], a => a[1]);
Now you can read from dictionary by key:
string hello = dict["hello"];
i have this path
C:\Users\sspl\Desktop\worldtaxi_14_march_2014_new\worldtaxi_12_march_2014_new\o_logo\img1.png
i want to select o_logo\img1.png from last of that string
how to do that
any help that will be appreciated.
in c# you can do this as
string str = #"folder2\folder2\o_logo\img1.png";
string sub = str.Substring(str.Substring(0,str.LastIndexOf(#"\")).LastIndexOf(#"\") + 1);
Hope it will help you.
We may use Java String class's split method to get the required output
public class GetFilename {
/**
* #param args
*/
private String instr = "C:\\Users\\sspl\\Desktop\\worldtaxi_14_march_2014_new\\worldtaxi_12_march_2014_new\\o_logo\\img1.png";
//private String instr = "C:/Users/sspl/Desktop/worldtaxi_14_march_2014_new/worldtaxi_12_march_2014_new/o_logo/img1.png";
private String getFileName(){
String filename="";
String[] splitarr = instr.split("\\\\");
//String[] splitarr = instr.split("/");
int splitarrlen = splitarr.length;
filename = splitarr[splitarrlen-2]+"\\"+splitarr[splitarrlen-1];
return filename;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GetFilename gfn = new GetFilename();
System.out.println(gfn.getFileName());
}
}
Care must be taken while using regular expressions. String's split method takes a regular expression as input. Special characters need to be escaped with a backward slash. Also it is better to use forword slash(/) as path seperator. To understand the simplicity of using "/" instead of "\" uncomment the lines which are commented, and also comment the previous line.
I am using "Externalize Strings" widget of Eclipse. On externalizing strings, a messages.properties file is generated with key value pairs.
Say the messages.properties looks like this:
Test_msg1=Add
Test_msg2=Remove
Test_msg3=Include
Say I have a file Test.java with code:
String add = Messages.getString("Test_msg1");
String remove = Messages.getString("Test_msg2");
String include = Messages.getString("Test_msg3");
Next, if I edit Test.java file and remove the two strings "remove" and "include" then I would want the messages.properties file to be updated such that Test_msg2 and Test_msg3 are removed. Is there a way to do this ? Or do I have to edit messages.properties file manually everytime I delete a string from a huge java file?
Thanks,
Sony
When you externalize strings from java file via 'Externalize dialog', you should get a Message.java and message.properties like below,
public class Message extends NLS {
private static final String BUNDLE_NAME = "com.xxx.ui.internal.Message"; //$NON-NLS-1$
//Generic Strings:
public static String Str1;
public static String Str2;
static {
loadMessages();
}
public static void loadMessages() {
NLS.initializeMessages(BUNDLE_NAME, Message.class);
}
}
Str1=Add
Str2=Remove
If no java code uses the string "Str1", you would find them and remove them via right clicking the Message.java or message.properties, then clicking the context menu item 'source' - 'find broken externalized strings'.