string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
string exeDir = Path.GetDirectoryName(exeFile);
string fileName = Path.Combine(exeDir, #"..\..\xml\SalesOrderXMLData.csv.xml");
Hello,
The above code works if the project is in, for example,
C:\Code\
but not if its in
C:\Documents and Settings\Naim\My Documents..
If i have the string, i would use escape characters where needed, but in this case, i dont know how to get around this.
Update: result fileName = "D:\Naim\My%20Documents\Visual%20Studio%202008\Projects\XML_Gen\XML_Gen\bin\Debug\..\..\xml\SalesOrderXMLData.csv.xml"
Any help appreciated.
Thanks
It's probably the URI. Use Assembly.GetEntryAssembly().Location, and pass it directly to Path.GetDirectoryName().
code below works, though I don't know why the above wasn't working. Changed AbsolutePath to LocalPath
string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).LocalPath;
string exeDir = Path.GetDirectoryName(exeFile);
string fileName = Path.Combine(exeDir, #"..\..\xml\SalesOrderXMLData.csv.xml");
Related
I have a file that contains :
String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"
I try to change the string change_variable with something else like
String url = "https://url_adress/v2.0/vpc/peerings?name=florian-testpeering-5"
But when I use :
sed 's/"https:\/\/url_adress\/v2.0\/vpc\/peerings?name/"https:\/\/url_adress\/v2.0\/vpc\/peerings?name=florian-testpeering-5"/'g
I Obtain :
String url = "https://url_adress/v2.0/vpc/peerings?name=florian-testpeering-5"=change_url"
What I did wrong ?
Edit :
To be more precise, I need to change the change_variable inside with a $peering who I declare before in my script.
The fact that you have forward slashes in the url, means that is better to use another character for the sed separator and so:
sed 's#String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"#String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"#g'
The normal / has been changed for #, allowing for easier reading and processing of the url.
Is this what you're trying to do?
awk 'index($0,"https://url_address/v2.0/vpc/peerings?name=change_variable") { sub(/change_variable/,"florian-testpeering-5") } 1' file
String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"
If I understand your edit, and you are saying you have your string in a variable at the beginning of your script, similar to:
var='String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"'
and you need to change the contents of the string replacing from name=... to the end with a new value, you can simply use bash parameter expansion with substring replacement, e.g.
var="${var/name=*/name=florian-testpeering-5\"}"
Now the variable var will contain:
String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"
You can do the same thing if the string you want to replace with is also stored in another variable, such as repl="lorian-testpeering-5", in that case your substring replacement would be:
var="${var/name=*/name=${repl}\"}"
(same result in var)
I have a ";" delimited string. I need to remove an entry from it. I tried to use slice but that does get sliced string but not the original-modified string.
Here is an example:
var str1: string = 'TY66447;BH31496;PA99001;';
var str2 = str1.slice(16, 23);
console.log(str1);
console.log(str2);
It gives:
TY66447;BH31496;PA99001;
PA99001
But what I want to achieve is TY66447;BH31496;
I am not sure if I am using the correct string method. Please guide how to achieve.
I don't understand what do you want, but it seems that you want:
str1.slice(0, 16);
i have a following string
var str="ArtShare$u002ETotalArtShares"
i want to replace this "$u002E" with "." so that my string will become
"ArtShare.TotalArtShares" to achieve this i used replace function
var str="ArtShare$u002ETotalArtShares"
var replace=str.replace(".","$u002E")
println("replaced string is "+replace)
but its not working following is printed on console
replaced string is ArtShare$u002ETotalArtShares
please guide me where i am doing wrong Thanks
UPDATE after the answer of user nyavro
i tried this
var str="ArtShare$u002ETotalArtShares"
var replace=str.replace("$u002E", ".")
println("replaced string is "+replace)
but output remains same
but the for testing i have tried this
var str1="ArtShare$u002ETotalArtShares"
var replace1=str1.replace("Total", ".")
println("replaced string is "+replace1)
the following is printed
replaced string is ArtShare$u002E.ArtShares
It means code is working when i replaces Total with "." but its not working when i am giving this part of string $u002E please help me i did not understand why is that happening
Update 2
I tried doing this
var str2="ArtShare$u002ETotalArtShares"
var replace2=str2.replace("u002E", ".")
println("replaced string is "+replace2)
the following is printed
replaced string is ArtShare$.TotalArtShares
after that i guess that $sign is causing the problem its not replacing please help me how can i replace that too
Switch arguments of str.replace:
var replace=str.replace("$u002E", ".")
#JasonLenderman was close:
var replace = str.replaceAll("\\$U002E", ".")
But he mentioned that he wasn't having a problem. I initially saw the same thing, but it appears there's a difference between $u002E and $U002E where the string gets special consideration if the "U" is capitalized. If you capitalize the "U" then the following doesn't work:
var replace = str.replace("\\$U002E", ".")
I grab a url and I want to parse and store two sections of the url
User/Confirmation?=QVNERkFTREY=&code=MTAvMjMvMjAxMyAxMjowMDowMCBBTQ==
So I want to start at (Confirmation?=) and stop at (&) and store the results
string = QVNERkFTREY
then for the second one I want to start at (&code=) and go to the end of the string and store that result
string = MTAvMjMvMjAxMyAxMjowMDowMCBBTQ==
I was have tried a few different things
Uri myUri = new Uri(Request.Url.AbsoluteUri);
string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("Confirmation?=");
string param2 = myUri.Query.Split();
Pretty sure I should be going a different route here but any help would be appreciate. I am going to continue to google search for now. I appreciate the help.
EDIT: I feel as though LINQ should be able to help me here..hmm
I would use HttpUtility.ParseQueryString rather than try to parse the URL myself.
String val = "User/Confirmation?=QVNERkFTREY=&code=MTAvMjMvMjAxMyAxMjowMDowMCBBTQ==";
System.Collections.Specialized.NameValueCollection parameters = System.Web.HttpUtility.ParseQueryString(val);
Console.Out.WriteLine(parameters[0]); // QVNERkFTREY=
Console.Out.WriteLine(parameters.Get("code"); // MTAvMjMvMjAxMyAxMjowMDowMCBBTQ==
You will need to add System.Web.dll, which you can read about here: Cannot add System.Web.dll reference
I have a string ="/show/search/All.aspx?Att=A1". How to get the last value after the 'Att=' in efficient way ?
You could do a split on the '=' character.
Example (in C#):
string line = "/show/search/All.aspx?Att=A1";
string[] parts = line.Split('=');
//parts[1] contains A1;
Hope this helps
If you're only dealing with this one URL then both of the other answers would work fine. I would consider using the HttpUtility.ParseQueryString method and just pull out the item you want by key.
Whatever an
efficient way
is...
Try this:
var str = "/show/search/All.aspx?Att=A1";
var searchString = "Att=";
var answer = str.Substring(str.IndexOf(searchString) + searchString.Length);