Conversion of a String to code
Hopefully this is phrased in such a way that it can be understandable and answered; how would one convert a String object to code? For example say a program had a user enter a class name and a method from a class, is there a means by which the text entered could be used as code? So if someone entered, "Math.abs(-1)" is it possible to derive from that the abs method and or the Math class?
There are other ways: you could use Groovy:
// To run this demo,
// download Groovy: http://groovy.codehaus.org/Download
// and stick the file 'groovy-all-1.6.3.jar' in your classpath.
public class GroovyDemo {
public static void main(String[] args) {
groovy.lang.GroovyShell shell = new groovy.lang.GroovyShell();
System.out.println(shell.evaluate("Math.abs(-1)")); // output: 1
}Note that you can compile any Java-method, -statement or -source file with the GroovyShell.
Similar Messages
-
String data code page - DB2 - Data Direct - Data Services
We are trying to connect to a DB2 source (Database product = DB2 OS/390 8.1.5) using Data Direct drivers and following error is showing up when we test the connectivity.
SQLConnect: Retrying Connect.
SQLConnect: Failed...
SQLSTATE = S1000
NATIVE ERROR = 0
MSG = [SAP BusinessObjects][ODBC DB2 Wire Protocol driver]String data code page conversion failed.
Wondering if anyone has had similar issue or if someone hasany ideas regarding how this can be resolved would be great.
Thanks for the helpCheck whether the DB2CODEPAGE env variable is set in your OS.
issue the following query against your database -
select codepage from syscat.tables where datatype='varchar'
This should return the corresponding codepage value.
In windows, create a user variable (environment variable) called DB2CODEPAGE and assign the value you got from the previous query.
If it is unix, use th setenv command
setenv DB2CODEPAGE 'cp1252'
, for instance
You may have to restart the machine once the variable is defined
Regards,
Shine -
ORA-03120 :two-task conversion routine:integer overflow Vendor code 3120
Hi,
I got below mentioned error message, while i run the procedure in sql developer
ORA-03120 :two-task conversion routine:integer overflow Vendor code 3120What version of the database are you on? 9.2.0.8 for a guess?
>
ORA-03120 is associated with bug 5671074 on Oracle Enterprise Edition; Version 9.2.0.8, occurring on any platform:
After applying the 9.2.0.8 patchset, compilation of functions and/or materialized view refreshes that reference remote databases via database links start failing with:
ORA-04052: error occurred when looking up remote object OMS.PREMISE@JEAUSER_OMPR_L.WORLD
ORA-00604: error occurred at recursive SQL level 1
ORA-03120: two-task conversion routine: integer overflow
ORA-02063: preceding line from JEAUSER_OMPR_L
Bug 5671074 "ORA-4052/ORA-3106 on Create / Refresh of Materialized View", can cause this problem. Contrary to the bug abstract and description, this bug does not just apply to materialized view creation and refresh. It can occur for any PL/SQL that references a remote object via database link where the 'Endianness' of the two platforms differs. If one platform is 'Big-Endian', and another platform is 'Little-Endian', then this bug can be triggered between them. A list of the endianness of different platforms can be obtained from the following query (note that the v$transportable_platform view is only available in 10.1 and above):
To resolve ORA-03120, this solution is given:
To implement the solution, it will be necessary to apply the one-off patch for Bug 5671074 to the 9.2.0.8 database. One-off patches to 9.2.0.8 for most platforms are already available for download on MOSC. Bug 5671074 to the 9.2.0.8 database. One-off patches to 9.2.0.8 for most platforms are already available for download on MOSC.
>
If not, post more information: {message:id=9360002} -
Hello,
I have two strings that are identical when printed to the console, however when I do a string compare they do not match. Is there any way to convert data that's held in a string to code so that I can see all the escape sequences?
ThanksFor clarification, this is what I wanted to do:-
public static void main(String[] args) throws UnsupportedEncodingException {
// TODO Auto-generated method stub
String testdata = "\tHello\nWorld!";
byte[] inbytes = testdata.getBytes("UTF-8");
for (byte b : inbytes) {
printChar(b);
public static void printChar(byte b) {
switch (b) {
case 8:
System.out.print("\\b");
break;
case 9:
System.out.print("\\t");
break;
case 10:
System.out.print("\\n");
break;
case 12:
System.out.print("\\f");
break;
case 13:
System.out.print("\\r");
break;
case 22:
System.out.print("\\\"");
break;
case 27:
System.out.print("\\\'");
break;
case 92:
System.out.print("\\\\");
break;
default:
System.out.print((char) b);
}{code} -
Conversion from a string to date type
I am trying for a servlet application , for which the requirement is as under :
from a html form through a input type text field , a date in string format , say 12/25/01 , is picked up.
this date is received in the servlet code , and is required to be updated in Microsoft Access Database Table under a field of data type "Date/Time"
here the problem is , the date's existing data type is String and the Access' field's Data type is Date/Time , therefore, it needs to be suitably converted to a date format before it is put into a sql statement .
please help , if any functionality is available for a conversion .
thanx and regardsyes stephen , taking a tip from you and another from a post from this forum yesterday on SQL Exception , i shifted my focus to java.sql.Date ,
now modifying my code as under works with perfect perfection ,
thanks stephen and joe schell for all the help
kapil
import java.text.*;
import java.sql.Date;
import java.sql.*;
class HardTrial{
public static void main(String args[]){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Date d = new Date(123456789);// initialising with some value
Date d1 = d.valueOf("1994-12-12");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:STUDENT_DSN");
stmt= con.createStatement();
PreparedStatement ps = con.prepareStatement("INSERT INTO NewTab VALUES (?,?)");
ps.setDate(1, d1);
ps.setString(2, "TESTING");
ps.executeUpdate();
rs = stmt.executeQuery("SELECT WHEN,WHAT FROM NewTab");
while (rs.next()){
System.out.println(rs.getString("WHEN")+ rs.getString("WHAT"));
}catch(Exception e){
System.out.println(e); -
Conversion of binary string into headecimal
Ho will i convert binary string into hexadecimal fromat
HI,
Thanks but the above module is not present my system.
I have number which needs to be converted into binary first and then into Hex.
I have written it code for conversion of decimal number into Binary.But i am not able to convert it into Hex.
My rough code is ....
types : begin of t_temp,
r1 type i,
end of t_temp.
data : ty_temp type standard table of t_temp ,
wa_temp type t_temp.
DATA : num TYPE i,
temp1 TYPE string,
temp2 TYPE string,
temp3 TYPE string,
temp4 TYPE x.
temp1 = 0.
temp2 = ''.
num = 64.
while num ne 1.
temp1 = num MOD 2.
num = num / 2.
If temp1 = 1.
num = num - 1.
endif.
concatenate temp1 temp2 into temp2 .
endwhile.
temp1 = 1.
concatenate temp1 temp2 into temp2 .
condense temp2 no-gaps .
WRITE : temp2 . -
Unicode: Conversion of a string of hexadecimal
Hello,
I need to know if there is any function that converts a string of hexadecimal characters and al reves.
In the event that there is, as I use this function?
I implemented the program code this instruction
Replace SEP_A0 with SEP_BL into wmara-mfrpn in byte mode.
And it is yielding the following error: wmara-mfrpn must be a byte-type field
(Type X or Xstring).
The fact is that I have to convert wmara-mfrpn to hex.
Any suggestions please?Hi,
Check the below FM'S
NLS_STRING_CONVERT_TO_SYS( Hex to char)
and NLS_STRING_CONVERT_FROM_SYS (char to hex)
Regards,
Nagaraj -
Conversion​: engineerin​g string to fractional string
Hello everyone
I am loading a text file with several columns that has text (informations about the file and column titles) and values in engineering format. After I load this file I use "spreadsheet string to array" to convert it to 2D array of strings.
I would like to leave all the "text" (informations about the file and column titles) unchanged, but I want all the "engineering values" to be converted to "fractional values". How do I convert an engineering string to a fractional string?
I will have to convert the whole file at once because different files have different positions for text and engineering values and because of that would be impossible to know the index of values and convert just them.
Thanks.
Dan07
Solved!
Go to Solution.Hi Dan,
conversion is done like that:
But you have to select, what is text and what is number, on your own. How should LabVIEW know about your file format?
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Change a string of code to narrative format
I have a field in OBIEE 11g that contains numeric codes (EXAMPLE 1;2;3)THe field can contain more then one value (EXAMPLE 1;2) Each code corresponds to a narrative descriptions (EXAMPLE: 1 = A, 2=b, 3=c) Currently I have a CASE STATEMENT that translate the code but only the first numeric value. My case statement is below:
CASE WHEN "METRIC" = 1 THEN 'A'
OR
CASE WHEN "METRIC" = 2 THEN 'B'
OR
CASE WHEN "METRIC" = 3 THEN 'C'
ELSE
NULL
END
This code only changes the one instance in the field to the appropriate defintion. What I need is a code that will read the field and change all the codes into the appropriate definition.
Example if the field contains 1;2 I need the output to be A;B
Is this possible to do?So I tried this and this is the error message I got.
SQL Issued: {call NQSGetQueryColumnInfo('SELECT TRANSLATE("Pending Claim - Miscellaneous"."Special Issue String", ''~49~'',''EXPRESS'') FROM DUAL FROM "VETSNET Operations Reports"')}
SQL Issued: SELECT TRANSLATE("Pending Claim - Miscellaneous"."Special Issue String", '~49~','EXPRESS') FROM DUAL FROM "VETSNET Operations Reports"
AND I am using ORACLE -
Anybody have some unicode string handling code I could use?
Text handling plugins are not working for some users, since Lua and Lr are not on the same page char-representation-wise.
For example, if you enter
À
in Lightroom, it's getting interpreted as
À
in Lua.
in non-plugin environment, one could just use slnunicode, however in plugin one needs pure lua solution.
Anybody?
ref: http://lua-users.org/wiki/LuaUnicode
RTry
Debug.pause( "uni-find", string.find( photo:getFormattedMetadata( 'title' ), 'À' ) )
when title field has an 'À' in it.
Instead of seeing the coordinates of the 'À' that is there, you'll see nil.
PS - this code looks promising (?) found at http://forums.gaspowered.com/viewtopic.php?f=19&t=29879
function conv2utf8(unicode_list)
local result = ''
local w,x,y,z = 0,0,0,0
local function modulo(a, b)
return a - math.floor(a/b) * b
end
for i,v in ipairs(unicode_list) do
if v ~= 0 and v ~= nil then
if v <= 0x7F then -- same as ASCII
result = result .. string.char(v)
elseif v >= 0x80 and v <= 0x7FF then -- 2 bytes
y = (v & 0x0007C0) >> 6
z = v & 0x00003F
y = math.floor(modulo(v, 0x000800) / 64)
z = modulo(v, 0x000040)
result = result .. string.char(0xC0 + y, 0x80 + z)
elseif (v >= 0x800 and v <= 0xD7FF) or (v >= 0xE000 and v <= 0xFFFF) then -- 3 bytes
x = (v & 0x00F000) >> 12
y = (v & 0x000FC0) >> 6
z = v & 0x00003F
x = math.floor(modulo(v, 0x010000) / 4096)
y = math.floor(modulo(v, 0x001000) / 64)
z = modulo(v, 0x000040)
result = result .. string.char(0xE0 + x, 0x80 + y, 0x80 + z)
elseif (v >= 0x10000 and v <= 0x10FFFF) then -- 4 bytes
w = (v & 0x1C0000) >> 18
x = (v & 0x03F000) >> 12
y = (v & 0x000FC0) >> 6
z = v & 0x00003F
w = math.floor(modulo(v, 0x200000) / 262144)
x = math.floor(modulo(v, 0x040000) / 4096)
y = math.floor(modulo(v, 0x001000) / 64)
z = modulo(v, 0x000040)
result = result .. string.char(0xF0 + w, 0x80 + x, 0x80 + y, 0x80 + z)
end
end
end
return result
end
or maybe this: (?)
function unichr(ord)
if ord == nil then return nil end
if ord < 32 then return string.format('\\x%02x', ord) end
if ord < 126 then return string.char(ord) end
if ord < 65539 then return string.format("\\u%04x", ord) end
if ord < 1114111 then return string.format("\\u%08x", ord) end
end
from http://stackoverflow.com/questions/7780179/what-is-the-way-to-represent-a-unichar-in-lua
R -
My last post is a bit ard to understand, I submit this easy code which cause the same trouble!
If anybody has some explanation I realy would be very grateful!!!!
Code : -----------------------------------------------------------------------------------------------
import java.io.*;
import java.util.*;
public class prova {
public static void main(String[] args) {
// builds a simple ArrayList object -----------------------------------------------------
ArrayList l=new ArrayList();
ArrayList l1=new ArrayList();
l1.add(new String("1-1"));
l1.add(new String("1-2"));
l1.add(new String("1-3"));
ArrayList l2=new ArrayList();
l1.add(new String("2-1"));
l1.add(new String("2-2"));
l.add(l1);
l.add(l2);
try{
// Serializes the ArrayList to a String -----------------------------------------------------
ByteArrayOutputStream ByteOutStream=new ByteArrayOutputStream();
ObjectOutputStream ObjBuff=new ObjectOutputStream(ByteOutStream);
ObjBuff.writeUnshared(l);
ObjBuff.flush();
ObjBuff.close();
String SerializedCommand=new String(ByteOutStream.toByteArray());
// Deserializes it -----------------------------------------------------
ByteArrayInputStream ByteInStream=new ByteArrayInputStream(SerializedCommand.getBytes());
ObjectInputStream ois=new ObjectInputStream(ByteInStream);
ArrayList result=(ArrayList)ois.readUnshared();
System.out.println(result);
catch (Exception e){e.printStackTrace();}
}hi, try it with xmlencoder and decoder!
// Serialize
ByteArrayOutputStream ByteOutStream=new ByteArrayOutputStream();
XMLEncoder ObjBuff=new XMLEncoder(ByteOutStream);
ObjBuff.writeObject(l);
ObjBuff.close();
String SerializedCommand=new String(ByteOutStream.toByteArray());
// Deserializes it
ByteArrayInputStream ByteInStream=new ByteArrayInputStream(SerializedCommand.getBytes());
XMLDecoder ois=new XMLDecoder(ByteInStream);
ArrayList result=(ArrayList)ois.readObject();
System.out.println(result);it should work.
greetings,
Chris -
Conversion from hex string to bytes withh out ascii
how to convert hex string to byte numbers without ascii codes,then all the converted bytes should come into a packets
rajkumar5 wrote:
how to convert hex string to byte numbers without ascii codes,then all the converted bytes should come into a packets
What people consider ASCII and Hex with strings varies so much, you pretty much need to supply an example. The best way is to create a VI with default data in the string control and indicator (to show what you want out). -
Runtime conversion of a string value to a primitive data type in java
can anyone of you give me an idea to convert a string value to a primitive data type during run time...i have the value and the type to which it has to be converted as String values...do you have any idea ,...pls share
String recvalvalue = inputval;
String recvartype = inputtype;
if (recvartype.equals("int")){
value0 = Integer.parseInt(recvalvalue);
else
if (recvartype.equals("double")){
value1 = Double.parseDouble(recvalvalue);
else
if(recvartype.equals("float")){
value2 = Float.parseFloat(recvalvalue);
else
if(recvartype.equals("Boolean")){
value3 = Boolean.parseBoolean(recvalvalue);
else
if(recvartype.equals("char")){
value4 = (char)recvalvalue.charAt(0);
else
if(recvartype.equals("String")){
value5 = recvalvalue;
else
if(recvartype.equals("byte")){
value6 = Byte.parseByte(recvalvalue);
//listA.add(6, value6);
// listA.g = value6;
else
if(recvartype.equals("long")){
value7 = Long.parseLong(recvalvalue);
else
if(recvartype.equals("short")){
value8 = Short.parseShort(recvalvalue);
} yes i can do this but the resultant value has to be assigned to a variable of a specific type which is here recvartype .....it has to be done dynamically automatically..if we know what type of data is that we can convert and assign to the type but we donot know when we run the program as the program will be supllied by someone and has to be executed -
Conversion of xml string to xml file
To convert xml string to xml file in java i used
Document XMLDoc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader("<root><main>Title</main></root&g t;")));
But it is showing an error as InputSource cannot be resolved
How to rectify thisI assume you mean there is a compiler error? (It helps if you explain your problem instead of just giving a vague description of it.) It sounds like you have to import InputSource. You do know about the import statements that go at the beginning of a Java class, don't you?
-
Conversion of a string to a number
Hi there,
I have a problem sending a String as a number..
I have a text field called score0 :-
var score = score0.text;
The string (score0.text) will have an "s" at the end as the time is counted in seconds and tenths, so I will be receiving something along the lines of "8.1s" as a value..
I would like to take score0.text, remove the "s" then *1000 the amount as a number before use..
Is this possible ? Thanks for any help in advance..You are welcome.
it is a Top Level class....
www.FlashDersi.com / Istanbul
Maybe you are looking for
-
Hi I have a directory that has files put into it. What I want to do is open/read these files in java and then do something to it and then move the file to another folder called passed or failed. What I dont know is how can I read a file who's name i
-
The one I'm trying to open up is about 150GB, and it has someting like 9,000 songs. But I cant open it up, and I dont want to lose years of collected music. Please help!
-
Can audiobooks (eg. Harry Potter which is soooo expensive) purchased from iTunes music store be loaded on multiple iPods similar to those purchased from audible.com?
-
Bought and Paid but Didn't download
I paid $15 for one of the nike + ipod workouts and only half of it downloaded and now it won't let me download the rest unless I pay for it again, bringing that to a grand total of $30 and the songs I did download I can't listen to because it says th
-
Embed fonts using the Edit Document Text tool
This question was posted in response to the following article: http://help.adobe.com/en_US/acrobat/pro/using/WS58a04a822e3e50102bd615109794195ff-7c75.w.h tml