lucif3r Posted April 18, 2011 Share Posted April 18, 2011 In my DB, the contents in the field will be like RMT0092X032_01AB , but I want to use charAt() func to judge the 8th character.if character is X then in report, the field is Lowif character is Y, then in field is Midif char is Z then is High in the field. Anyone can show me how to write the code? Using Scriptlet is a good option?Snytax, please. Thanks, everyone. M too green to Java.... Link to comment Share on other sites More sharing options...
kolaitis Posted April 18, 2011 Share Posted April 18, 2011 Suggestion only for lowerCase / upperCase.Create var : V1, classType: java.lang.Character, expression: new Character(yourFildName.chartAt(7))Create another var : V2, classType: java.lang.String, expression: $V{V1}.toString().equalsIgnoreCase("X") ? {yourFildName}.toLowerCase() : {yourFildName}.toUpperCase()drag V2 on your band. Mind Eval. time !For Mid print, create field using smaller fonts with printWhenExpression.I hope it will works... Link to comment Share on other sites More sharing options...
lucif3r Posted April 19, 2011 Author Share Posted April 19, 2011 Errr, I did not mean Uppercase or Lowercase. I just want the output is "High" , "Mid", and "Low"In Java, the logic suppose to be like this: if field.chatAt( 7 ).equalsIgnoreCase("X") output("Low")else if field.charAt( 7 ).equalsIgnoreCase("Y") output ("Mid") else output("High") I don't know why, when I use .charAt() func, the number in quotes always underlined, marked as an error.I change the lang from Groovy to Java, but it is still there.By the way, I use iReport 4.0.1 Thanks for the reply, I will keep trying.Post Edited by lucif3r at 04/19/2011 01:00 Link to comment Share on other sites More sharing options...
jpauze Posted April 19, 2011 Share Posted April 19, 2011 This should work for you. $F{field}.length() < 7 ? "Unknown" : $F{field}.toUpperCase().charAt(7) == 'X' ? "Low" : $F{field}.toUpperCase().charAt(7) == 'Y' ? "Mid" : "High" Added the field length check up front to make sure the charAt index doesn't fail if the string doesn't have an index of 7. Link to comment Share on other sites More sharing options...
lucif3r Posted April 21, 2011 Author Share Posted April 21, 2011 Thanks, i will give a shot Link to comment Share on other sites More sharing options...
lucif3r Posted April 21, 2011 Author Share Posted April 21, 2011 I tried. But I can not preview the report I generate. I click "preview", it will flash back to designer GUI.But if I remove this expression, it will be fine. I can preview my report normally.Very weird...Post Edited by lucif3r at 04/21/2011 04:53 Link to comment Share on other sites More sharing options...
jpauze Posted April 21, 2011 Share Posted April 21, 2011 Not sure what to say, to verify the syntax I put together a quick sample report, same statement, I just changed the position of of the character I'm looking for and the character to find. In my example I am looking for the character 0 and 1 in the 11 position of the text and displaying found 0 or found 1 depending on which character exists. See attached sample.This was the expression I used.$F{host_name}.length() < 11 ? "Unknown" : $F{host_name}.toUpperCase().charAt(10) == '0' ? "Found 0" :$F{host_name}.toUpperCase().charAt(10) == '1' ? "Found 1" : "Not Found"I typically don't preview within iReport because most of my data is coming from a java class in our application, have you tried running outside of iReport preview natively in the application you normally view reports in? are there any error messages displayed on compile or execution? Post Edited by jpauze at 04/21/2011 14:55 Link to comment Share on other sites More sharing options...
jpauze Posted April 22, 2011 Share Posted April 22, 2011 Did I mention my report language is set to java? Link to comment Share on other sites More sharing options...
lucif3r Posted April 22, 2011 Author Share Posted April 22, 2011 Thanks, jpauze. i will try again.I am new to iReport, obviously, so $F{host_name}.length() < 11 ? "Unknown" : $F{host_name}.toUpperCase().charAt(10) == '0' ? "Found 0" :$F{host_name}.toUpperCase().charAt(10) == '1' ? "Found 1" : "Not Found"this is the expression for the textField, right, or this is the expression for Variable? I remember if it is for variable, it supposed to have "new" keyword, right? Link to comment Share on other sites More sharing options...
jpauze Posted April 22, 2011 Share Posted April 22, 2011 Correct, this is the field expression, variable is not required Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now