Exporting emails from Outlook - comma in subject line - outlook

I'm trying to export email from Outlook(2010) into a CSV file, but there are emails with a comma in the subject line.
Is there a way to deal with this? I can't find an option to change the delimiter to something else.
Thanks

You can use the VBA Replace function.
Eg, this takes myString and replaces the comma with a dash.
Dim myString As String
myString = "Test subject, with comma"
myString = Replace(myString, ",", "-")
myString becomes "Test subject- with comma"

If the value contains a comma, enclose the value in quotes. If you have a quote, replace it with a double quote. E.g a value like
Weird, encoded "subject"
becomes
"Weird, encoded ""subject"""

Related

How to remove the last character from a string in Jmeter

I have a string like below and am trying to remove the last character from that string. can someone please help on this
what if I have a lengthy string and I want to only remove the last character of my string.
Example: "city": "Winston Salem","state": "NC","zip": "27127","country": " "}}
and I want to only remove the last '}'.
Use a String method like replace:
String newString = oldString.replace("}}", "}")
if that´s case or another one; you can use anywhere of methods of String API only if casts to String

Phoenix string interpolation containing \n and name="abc" in HTML

I want to generate HTML content in phoenix. I'm not able to use interpolation while adding name="abc". I get an error at ".
Using \ in text also shows the \, e.g. text = "This is an name=\"abc\" string" gives text = "This is an name=\"abc\" string".
Can anyone please suggest how I can have a raw string containing name="abc"?
The string does contain only name="abc", the problem is that when you see it in the terminal, Elixir escapes the double quotes, so you can copy and paste it to your code. If in doubt, use IO.puts(text), and it will print the text without doing any changes to it:
iex(1)> text = "This is an name=\"abc\" string"
"This is an name=\"abc\" string"
iex(2)> IO.puts text
This is an name="abc" string
:ok
If you want to interpolate some double quotes into a string, you might try this:
iex(1)> text = "This is a name=#{"abc"} string"
"This is a name=abc string"
That didn't work. You need to do something extra:
iex(16)> text = "This is a name=#{"\"abc\""} string"
"This is a name=\"abc\" string"
When you write something like this:
text = "This is a name="abc" string"
You should wonder how is it that elixir knows that the last quote is the quote that terminates the string. In other words, why doesn't elixir think that this is your string:
text = "This is a name="
and the rest of the line is just garbage that doesn't follow elixir's syntax? In order to tell elixir that the double quote after the = sign is not the end of the string--but that it's just another character within the string--you escape the double quote, like this:
text = "This is a name=\"abc\" string"
Now, elixir will see the double quote after string as the termination of the string.
Next, it is a complete hassle to escape double quotes within a string, so elixir provides a means of avoiding that with the ~s sigil:
iex(17)> text = ~s{This is a name="abc" string}
"This is a name=\"abc\" string"
With the ~s sigil, you can use various character pairs to surround your string, e.g. () or <> or | | or / /. You need to use a character pair that is not found within the string--otherwise you will run into the same problem as with interior double quotes.
Finally, you can prove that the string name=\"abc\" has only 10 characters, i.e. the characters name="abc", like this:
iex(13)> s1 = ~s{name="abc"}
"name=\"abc\""
iex(14)> String.length s1
10

Unable to substitute escaped characters in string

I have this string:
str = "no,\"contact_last_name\",\"token\""
=> "no,\"contact_last_name\",\"token\""
I want to remove the escaped double quoted string character \". I use gsub:
result = str.gsub('\\"','')
=> "no,\"contact_last_name\",\"token\""
It appears that the string has not substituted the double quote escape characters in the string.
Why am I trying to do this? I have this csv file:
no,"contact_last_name","token",company,urbanization,sec-"property_address","property_address",city-state-zip,ase,oel,presorttrayid,presortdate,imbno,encodedimbno,fca,"property_city","property_state","property_zip"
1,MARIE A JEANTY,1083123,,,,17 SW 6TH AVE,DANIA BEACH FL 33004-3260,Electronic Service Requested,,T00215,12/14/2016,00-314-901373799-105112-33004-3260-17,TATTTADTATTDDDTTFDDFATFTDDDTTFADTTDFAAADDATDAATTFDTDFTTAFFTTATFFF,017,DANIA BEACH,FL, 33004-3260
When I try to open it with CSV, I get the following error:
CSV.foreach(path, headers: true) do |row|
end
CSV::MalformedCSVError: Illegal quoting in line 1.
Once I removed those double quoted strings in the first row (the header), the error went away. So I am trying to remove those double quoted strings before I run it through CSV:
file = File.open "file.csv"
contents = file.read
"no,\"contact_last_name\",\"token\" ... "
contents.gsub!('\\"','')
So again my question is why is gsub not removing the specified characters? Note that this actuall does work:
contents.gsub /"/, ""
as if the string is ignoring the \ character.
There is no escaped double quote in this string:
"no,\"contact_last_name\",\"token\""
The interpreter recognizes the text above as a string because it is enclosed in double quotes. And because of the same reason, the double quotes embedded in the string must be escaped; otherwise they signal the end of the string.
The enclosing double quote characters are part of the language, not part of the string. The use of backslash (\) as an escape character is also the language's way to put inside a string characters that otherwise have special meaning (double quotes f.e.).
The actual string stored in the str variable is:
no,"contact_last_name","token"
You can check this for yourself if you tell the interpreter to put the string on screen (puts str).
To answer the issue from the question's title, all your efforts to substitute escaped characters string were in vain just because the string doesn't contain the character sequences you tried to find and replace.
And the actual problem is that the CSV file is malformed. The 6th value on the first row (sec-"property_address") doesn't follow the format of a correctly encoded CSV file.
It should read either sec-property_address or "sec-property_address"; i.e. the value should be either not enclosed in quotes at all or completely enclosed in quotes. Having it partially enclosed in quotes confuses the Ruby's CSV parser.
The string looks fine; You're not understanding what you're seeing. Meditate on this:
"no,\"contact_last_name\",\"token\"" # => "no,\"contact_last_name\",\"token\""
'no,"contact_last_name","token"' # => "no,\"contact_last_name\",\"token\""
%q[no,"contact_last_name","token"] # => "no,\"contact_last_name\",\"token\""
%Q#no,"contact_last_name","token"# # => "no,\"contact_last_name\",\"token\""
When looking at a string that is delimited by double-quotes, it's necessary to escape certain characters, such as embedded double-quotes. Ruby, along with many other languages, has multiple ways of defining a string to remove that need.

How to delete a substring after a certain word?

I have a long String and want to delete the part of the String that comes after a word and I'm looking for the gsub! command that does that. I would appreciate it if you could provide it.
For reference:
I know that the command to delete the part of the String (the String is called contents) that comes before the word "body" is:
contents.gsub!(/.*?(?=body)/im, "")
Thanks.
This code:
"this has a word in it".gsub! /(word).*/, $1
Will change the string to "this has a word"
The "word" in brackets is the first argument returned by the regex, and $1 returns that argument.
See the Ruby docs for gsub
Going by your regex, that requires the / in body to be escaped, I'm assuming you mean every after
contents = "Stuff before </body> stuff after"
contents.gsub(/(?<=\/body>).+/, "")
=> "Stuff before </body>"

Ruby string sub without regex back references

I'm trying to do a simple string sub in Ruby.
The second argument to sub() is a long piece of minified JavaScript which has regular expressions contained in it. Back references in the regex in this string seem to be effecting the result of sub, because the replaced string (i.e., the first argument) is appearing in the output string.
Example:
input = "string <!--tooreplace--> is here"
output = input.sub("<!--tooreplace-->", "\&")
I want the output to be:
"string \& is here"
Not:
"string & is here"
or if escaping the regex
"string <!--tooreplace--> is here"
Basically, I want some way of doing a string sub that has no regex consequences at all - just a simple string replace.
To avoid having to figure out how to escape the replacement string, use Regex.escape. It's handy when replacements are complicated, or dealing with it is an unnecessary pain. A little helper on String is nice too.
input.sub("<!--toreplace-->", Regexp.escape('\&'))
You can also use block notation to make it simpler (as opposed to Regexp.escape):
=> puts input.sub("<!--tooreplace-->") {'\&'}
string \& is here
Use single quotes and escape the backslash:
output = input.sub("<!--tooreplace-->", '\\\&') #=> "string \\& is here"
Well, since '\\&' (that is, \ followed by &) is being interpreted as a special regex statement, it stands to reason that you need to escape the backslash. In fact, this works:
>> puts 'abc'.sub 'b', '\\\\&'
a\&c
Note that \\\\& represents the literal string \\&.

Resources