replacing a hardcoded path
string antcbatchpath = @"""C:\Work\6.70_Extensions\release\SASE Lab Tools\ANT Builds\antc.bat"""
in the above string, if i would like to replace 6.70_Extensions
with buildStream
how do i do it?
buildStream
can be 6.70_Extensions
, 7.00_Extensions
or 7.10.000_Tip
etc
buildStream
is obtained from combobo开发者_开发知识库x selection
If I were you, I would do
string antcbatchpath = string.Format(@"""C:\Work\{0}\release\SASE Lab Tools\ANT Builds\antc.bat""", buildStream);
string.Format is a highly useful method which I use all the time. To give credit where credit is due, I borrowed the link from Devendra's answer.
String antcbatchpath = @"""c:\work\{0}\release\SASE Lab Tools\ANT Builds\antc.bat""";
String newPath = String.Format(antcbatchpath, buildStream);
Use string.Format,
if (myComboBox.SelectedValue != null)
{
string buildStream = myComboBox.SelectedValue.ToString().Trim();
// Assuming your build stream is not culture dependent
// {0} is the placement handler for the first argument
string.Format(CultureInfo.InvariantCulture, @"""C:\Work\{0}\release\SASE Lab Tools\ANT Builds\antc.bat""",
buildStream);
}
精彩评论