Handling of Double or Single Quotation Marks in ConversationTopic

  • Thread starter Thread starter RN
  • Start date Start date
R

RN

Hi,

I have an issue here in using the Restrict method to confine my result set
to a specific topic. In both cases below EmailSubject is a string passed in
to a method that handle the statement.

Case 1 (use of escaped double quotes in search string):
MyMailItems = SelectedFolder.Items.Restrict("[ConversationTopic]=\"" +
EmailSubject + "\"");
---> This will fail if there is any double quotation mark in the
ConversationTopic field.

Whereas

Case 2 (use of single quotation mark in search string):
MyMailItems = SelectedFolder.Items.Restrict("[ConversationTopic]='" +
EmailSubject + "'");
---> This will fail if there is any single quotation mark in the
ConversationTopic field.

Both Case 1 and Case 2 work fine if there is no single or double quotation
marks present in the ConversationTopic field.

So I got a problem in either case. Does anyone have any suggestion in
handling or bypassing the presence of either the double or the single
quotation marks in ConversationTopics?

Thanks.
Robin
 
Hi Ken,

I did. What I did was to detect the presence of single quote in
ConversationTopic then I will use double quotes in my Restrict criteria. And
if I detected the presence of double quote in ConversationTopic then I will
use single quotes in my Restrict criteria. This works out well. But the
problem is when both the single and double quotes are present in
ConversationTopic then I don't know how to write my Restrict criteria.

Regards,
Robin

Ken Slovak - said:
Test it both ways using an OR clause.




RN said:
Hi,

I have an issue here in using the Restrict method to confine my result set
to a specific topic. In both cases below EmailSubject is a string passed
in
to a method that handle the statement.

Case 1 (use of escaped double quotes in search string):
MyMailItems = SelectedFolder.Items.Restrict("[ConversationTopic]=\"" +
EmailSubject + "\"");
---> This will fail if there is any double quotation mark in the
ConversationTopic field.

Whereas

Case 2 (use of single quotation mark in search string):
MyMailItems = SelectedFolder.Items.Restrict("[ConversationTopic]='" +
EmailSubject + "'");
---> This will fail if there is any single quotation mark in the
ConversationTopic field.

Both Case 1 and Case 2 work fine if there is no single or double quotation
marks present in the ConversationTopic field.

So I got a problem in either case. Does anyone have any suggestion in
handling or bypassing the presence of either the double or the single
quotation marks in ConversationTopics?

Thanks.
Robin
 
Hmmm. Have you tried doubling up any single quotes to escape them when
they're in the EmailSubject string? Then you could try just using single
quotes surrounding the EmailSubject part of the restriction.

string test = EmailSubject;

// first clause has single quote within double quotes,
// second clause has 2 single quotes within double quotes.
EmailSubject = test.Replace("'", "''");
 
No luck. I think the problem here is the property of ConversationTopic is
readonly. Even if it is a read/write property it will be a hassle to replace
each and everyone of the same ConversationTopic due to performance issues.
Another issue is that the Restrict method will hunt for all identical
ConversationTopic in Outlook folders and thus changing a particular instance
of the ConversationTopic will not help.

Robin
 
I wasn't suggesting trying to change the read-only ConversationTopic
property. I was suggesting trying massaging the EmailSubject variable that
way. Other than that I have no other suggestions.
 
Back
Top