/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation, */ /* version 2.1 of the License. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with this library; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ // StringToFormulaForString.cs // Copyright (c) Microsoft Corporation. All rights reserved. // // This class demonstrates how to convert a string to a Visio formula // string. using System; namespace lido.VSVisioEditor { /// This class demonstrates how to convert a string to a Visio /// formula string. public class StringToFormulaString { /// This constructor is intentionally left blank. public StringToFormulaString() { // No initialization is required. } /// This method converts the input string to a Visio string by /// replacing each double quotation mark (") with a pair of /// double quotation marks ("") and then adding double quotation /// marks around the entire string. /// Input string that will be converted /// to Visio string /// A converted Visio string that can be programmatically assigned /// to a ShapeSheet cell is returned. Note that the string cannot be directly /// pasted into a ShapeSheet cell because it doesn't have an "=" at its /// beginning. public string StringToFormulaForString(string inputValue) { string result = ""; string quote = "\""; string quoteQuote = "\"\""; try { result = inputValue != null ? inputValue : String.Empty; // Replace all (") with (""). result = result.Replace(quote, quoteQuote); // Add ("") around the whole string. result = quote + result + quote; } catch (Exception err) { System.Diagnostics.Debug.WriteLine(err.Message); throw; } return result; } } }