Welcome Guest Search | Active Topics | Members | Log In | Register

EscapeString - A Command to Escape Quotes in a String Options · View
AutoCoDEV
Posted: Thursday, April 17, 2008 12:14:33 PM
Rank: Advanced Member
Groups: Member

Joined: 4/17/2008
Posts: 2
Points: -91
Location: Spain
String quotes are sometimes a mess when they have to be escaped with \"
This command converts a selected literal string in a escaped string.

Code:
    <CommandCode language="csharp">

      <Render>
        Selection.Text = Selection.Text.Replace("\"", "\\\"");
      </Render>

    </CommandCode>


And why not escape also the slashes?

Code:
      <Render>
        string selection = Selection.Text;
        selection = selection.Replace("\\", "\\\\");
        selection = selection.Replace("\"", "\\\"");
        Selection.Text = selection;
      </Render>


Here is the complete command template:

Code:
<?xml version="1.0"?>
<Commands xmlns="http://schemas.devprojects.net/AutoCode/v3.0">
  <Command name="EscapeString" priority="50">
    <CommandBehavior>
      <CommandLine shortcut="esc" />
      <ActiveDocument extensions="*"/>
    </CommandBehavior>

    <CommandInfo>
      <LanguageCategory>Common</LanguageCategory>
      <Category>Strings</Category>
      <Usage>esc</Usage>
      <Description>Escape quotes in a string</Description>
      <Author>AutocoDev</Author>
      <HelpUrl>www.devprojects.net</HelpUrl>
    </CommandInfo>

    <CommandCode language="csharp">

      <Render>
        Selection.Text = Selection.Text.Replace("\"", "\\\"");
      </Render>

    </CommandCode>
  </Command>
</Commands>


To use this command:

1. Select a string excluding the beginning and end quote characters
2. Press Ctrl+Enter
3. Write in the AutoCode InputBox "esc" and press enter

The selected string will be escaped.


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008