Sunday 1 March 2015

C# string replace with escape characters



Input argumenets
#to=test@gmail.com #subject="Welcome to" #server=mail.gmail.com #port=8080 #from=from@gmail.com

#to="test@gmail.com" #subject="Welcome" #server="mail.gmail.com" #port="8080" #from="from@gmail.com"

#to=\"test@gmail.com\" #subject=\"Welcome\" #server=\"mail.gmail.com\" #port=\"8080\" #from=\"from@gmail.com\"

Expected input string to application.
#to=\"test@gmail.com\" #subject=\"Welcome\" #server=\"mail.gmail.com\" #port=\"8080\" #from=\"from@gmail.com\"

Application will get Input argumenets in any format of give 3 type, but business will work for only one type of format, so we have to manipulate rest of the 2 types to 3rd type.

Solution:
I am going to write one exe, to manipulate input args.
Open Visual studio
Create new console project: StringEscapeCharacters
Open: Program.cs file

Please find my code...


Now i have to pass arguments to my exe, i can to multiple ways..
1st way: Open solution explorer, right click on project.
Click on: Properties
Click on: Debug
Under Start Options:
Command line arguments: <Enter arguments>
Ex:
#to=test@gmail.com #subject="Welcome to exe" #server=mail.gmail.com #port=8080 #from=from@gmail.com


You will get out put as in the log file:C:\Temp\mylog.log
#to="test@gmail.com" #subject="Welcome to exe" #server="mail.gmail.com" #port="8080" #from="from@gmail.com"

2nd way passing args:
Build the application.
now go to bin/debug folder,
you will see: StringEscapeCharacters.exe
execute this exe from cmd and pass args.
ex: StringEscapeCharacters.exe #to=test@gmail.com #subject="Welcome to exe" #server=mail.gmail.com #port=8080 #from=from@gmail.com