This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to accomplish variable interpolation in a string

 
abhinav sinha
Greenhorn
Posts: 22
  • 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
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • 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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic