File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to accomplish variable interpolation in a string

 
abhinav sinha
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not able to interpolate a variable.I am new to Java programming so I am do not know about it.Here is a part of sample code which I am using -

-----------------------------------------------------------------
<code>
public void itemStateChanged(java.awt.event.ItemEvent e) {
if (e.getStateChange() == e.SELECTED) {
String abh=(String)e.getItem();
System.out.println("the script chosen by abhinav is "+ abh);
File f = new File("scripts\\"+e.getItem());
if (! f.exists())
{
JOptionPane.showMessageDialog(null,e.getItem()+" does not exists","LAB DIALER ERROR", 1);
}
String cmd = "perl scripts/abh";
Process p=null;
p=Runtime.getRuntime().exec(cmd);

<\code>

The above program is not able to run the perl script because it is not able to interpolate the value of String abh in the String cmd.Please tell me how to do it.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by "interpolate". Do you mean "concatenate"? I guess you'd want to do this:

String cmd = "perl scripts/" + abh;
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic