RETURN (REPLACE(REPLACE(REPLACE(@input, @class_text, '~~|~'), @id_text, @class_text), '~~|~', @id_text))
@入力は文字列です。同じパラメータを持つC#でこれを変換する方法は、t-sqlをCに置き換えるコードを変換します。
...
@class_text is class_text in C#, etc..
RETURN (REPLACE(REPLACE(REPLACE(@input, @class_text, '~~|~'), @id_text, @class_text), '~~|~', @id_text))
@入力は文字列です。同じパラメータを持つC#でこれを変換する方法は、t-sqlをCに置き換えるコードを変換します。
...
@class_text is class_text in C#, etc..
input = input.Replace(class_text, "~~|~").Replace(id_text, class_text).Replace("~~|~", id_text);
簡単なこと
T-SQLのREPLACE
は、実際には異なる引数を持っているよう。それはstring2
内string1
を探している、例えば、
REPLACE(string1, string2, replaceText)
、それが一般的であるのに対し:
string1.Replace(string2, replaceText)
...あなたはstring1
にstring2
を探している.NETで。大量の文字列を置換する場合は、StringBuilder
をお勧めします。
var builder = new Stringbuilder(input);
builder = builder.Replace(class_text, "~~|~").Replace(id_text, class_text).Replace("~~|~", id_text)
string result = builder.ToString();
1)は、文字列
String myOldString = "No way";
2作る)
String myNewString = myOldString.Replace("No", "Yes");
置き換える機能を使ってここでより詳細な情報については、MSDNのです:http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx#Y480
EDIT ここにいますthあなたのポストから電子データ:
String myInput = "whatever @input equals"
String myclass_text = "whatever @class_text equals"
String myid_text = "whatever @id_text equals"
String myString = myInput.replace(myclass_text, "~~|~")
myString = myString.replace(myid_text, class_text)
myString = myString.replace("~~|~", myid_text)
またはオールインワン(私はC#は、このようにあなたピギーバックをすることができます場合は知っているが、ワンライナーを好む場合は、それを試して与えていない:
をString myString = myInput.replace(myclass_text, "~~|~").replace(myid_text, myclass_text).replace("~~|~", myid_text)
は、元の質問で要求されている可能性がC#にTSQLを、変換さ
How to change string element position in C#
/// <summary>
/// Given a line of text, swap position of class and id tags.
/// Id should always precede class tag
///
/// </summary>
/// <param name="input"><td class="m92_t_col5" id="preis_0">xx</td></param>
/// <returns><td id="preis_0" class="m92_t_col5">xx</td></returns>
public static string SwapClassAndId(string input)
{
string output = string.Empty;
int classOrdinal = 0;
int classOridnalEndQuotes = 0;
string classText = string.Empty;
int idOrdinal = 0;
int idOrdinalEndQuotes = 0;
string idText = string.Empty;
classOrdinal = input.IndexOf("class=");
classOridnalEndQuotes = input.IndexOf("\"", classOrdinal + 7) + 1;
idOrdinal = input.IndexOf("id=");
idOrdinalEndQuotes = input.IndexOf("\"", idOrdinal + 4) + 1;
if (idOrdinal < classOrdinal)
{
return input;
}
classText = input.Substring(classOrdinal, classOridnalEndQuotes - classOrdinal);
idText = input.Substring(idOrdinal, idOrdinalEndQuotes - idOrdinal);
output = input.Replace(classText, "~~|~").Replace(idText, classText).Replace("~~|~", idText);
return output;
}
あなたはより良いあなたは、HTTPをしようとしているアプローチではなく、解決しようとしている問題を識別することによって提供される可能性があります://積み重ねverflow.com/questions/7059893/mssql-tsql-procedure-replace-orderおよびhttp://stackoverflow.com/questions/7065469/how-to-change-string-element-position-in-c – billinkc