jeremychan
jeremychan

Reputation: 4459

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 combobox selection

Upvotes: 0

Views: 243

Answers (3)

Devendra D. Chavan
Devendra D. Chavan

Reputation: 9011

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);
 }

Upvotes: 1

Phil
Phil

Reputation: 6679

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.

Upvotes: 3

ChrisLively
ChrisLively

Reputation: 88054

String antcbatchpath = @"""c:\work\{0}\release\SASE Lab Tools\ANT Builds\antc.bat""";

String newPath = String.Format(antcbatchpath, buildStream);

Upvotes: 1

Related Questions