У меня есть строка:
Apple1231|C:\asfae\drqw\qwer|2342|1.txt
У меня есть следующий код:
Regex line2parse = Regex.Match(line,@"(\|)(\|)(\|)(\d)");
if (line2parse < 2)
{
File.AppendAllText(workingdirform2 + "configuration.txt",
То, что я хочу смочь сделать, заменить каждый |
после первого |
с \
Таким образом, я хочу выписать
Apple1231|C:\asfae\drqw\qwer\2342\1.txt
+1 Джон. Очевидно, регулярные выражения не лучшим решением здесь, но вот мой взять:
string original = @"Apple1231|C:\asfae\drqw\qwer|2342|1.txt";
Regex pattern = new Regex(@"(?<=.*\|)(?'rep'[^\|]*)\|");
string result = pattern.Replace(original, @"${rep}\");
Это более общий, чем строго необходимо, потому что он будет обрабатывать произвольное количество замены.
Я не использовал его с PHP, но doxygen утверждает, что поддерживает язык.
-121--1608239-Вот один, который я написал в колледже. Он также включает поддержку отрицательных чисел. Я знаю, что есть несколько способов укоротить и/или очистить, но эй, это хорошо работает для любого целого!
/**
Converts an integer to its textual representation.
@param num the number to convert to a textual representation
@param depth the number of times this has been recursed
*/
function readNumber($num, $depth=0)
{
$num = (int)$num;
$retval ="";
if ($num < 0) // if it's any other negative, just flip it and call again
return "negative " + readNumber(-$num, 0);
if ($num > 99) // 100 and above
{
if ($num > 999) // 1000 and higher
$retval .= readNumber($num/1000, $depth+3);
$num %= 1000; // now we just need the last three digits
if ($num > 99) // as long as the first digit is not zero
$retval .= readNumber($num/100, 2)." hundred\n";
$retval .=readNumber($num%100, 1); // our last two digits
}
else // from 0 to 99
{
$mod = floor($num / 10);
if ($mod == 0) // ones place
{
if ($num == 1) $retval.="one";
else if ($num == 2) $retval.="two";
else if ($num == 3) $retval.="three";
else if ($num == 4) $retval.="four";
else if ($num == 5) $retval.="five";
else if ($num == 6) $retval.="six";
else if ($num == 7) $retval.="seven";
else if ($num == 8) $retval.="eight";
else if ($num == 9) $retval.="nine";
}
else if ($mod == 1) // if there's a one in the ten's place
{
if ($num == 10) $retval.="ten";
else if ($num == 11) $retval.="eleven";
else if ($num == 12) $retval.="twelve";
else if ($num == 13) $retval.="thirteen";
else if ($num == 14) $retval.="fourteen";
else if ($num == 15) $retval.="fifteen";
else if ($num == 16) $retval.="sixteen";
else if ($num == 17) $retval.="seventeen";
else if ($num == 18) $retval.="eighteen";
else if ($num == 19) $retval.="nineteen";
}
else // if there's a different number in the ten's place
{
if ($mod == 2) $retval.="twenty ";
else if ($mod == 3) $retval.="thirty ";
else if ($mod == 4) $retval.="forty ";
else if ($mod == 5) $retval.="fifty ";
else if ($mod == 6) $retval.="sixty ";
else if ($mod == 7) $retval.="seventy ";
else if ($mod == 8) $retval.="eighty ";
else if ($mod == 9) $retval.="ninety ";
if (($num % 10) != 0)
{
$retval = rtrim($retval); //get rid of space at end
$retval .= "-";
}
$retval.=readNumber($num % 10, 0);
}
}
if ($num != 0)
{
if ($depth == 3)
$retval.=" thousand\n";
else if ($depth == 6)
$retval.=" million\n";
if ($depth == 9)
$retval.=" billion\n";
}
return $retval;
}
-121--1699033- Я бы не использовал Regex, но IndexOf (), чтобы найти сначала «|», затем заменить на .Substring () от этой позиции плюс 1 до конца... априори она должна работать лучше - но, как всегда бывает с исполнением, реальность удивляет ☺
Так как вы попросили регенцию:
var result = Regex.Replace( line, @"(.+?)\|(.+?)\|(.+?)\|(.+?)", "$1|$2\\$3\\$4");
Вы можете сделать это без Regex:
string line = @"Apple1231|C:\asfae\drqw\qwer|2342|1.txt";
string[] parts = line.Split('|');
string clean = parts[0] + "|" + string.Join(@"\", parts, 1, parts.Length - 1);
STRING.JOIN CALL использует перегрузку, которая позволяет указывать индекс запуска, чтобы пропустить первый элемент.
select orgname, count(*) as dupes, id
from organizations
where orgname in (
select orgname
from organizations
group by orgname
having (count(*) > 1)
)
group by orgname, id
-121--596891- Да, он будет вызван для любого типа файлов.
В этих модулях типично фильтровать все, что вас не интересует, например, проверяя, содержит ли «»/_ layouts« »в SharePoint.
-121--4667807-Полностью не протестирован, но попробуйте
fixed = Regex.Replace(unfixed.replace("|", @"\"), @"\\", "|", 1);
превратить все прутки в косые, а затем превратить первую косую черту обратно в пруток.
OfficeAutopilot имеет интересную версию webhooks. они используют свой интерфейс правил для запуска публикаций API. Может срабатывать в ответ на любое системное событие.. электронная почта открывается, щелкает, посещает страницу, покупает и т.д.
-121--3384094-YOu может применить логику с помощью триггера. Тогда независимо от того, как будет изменена запись, будет заполнен только один из полей.
Вы также могли бы иметь таблицу PeopleAsset и таблицу StartAsset, но у вас была бы проблема обеспечения того, что только один из них имеет запись.
-121--3909834-Вот код, который должен сделать трюк:
Regex MyRegex = new Regex( @"(.+\|)(.+)\|(\d{1,})\|(.+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); // This is the replacement string string MyRegexReplace = @"$1$2\$3\$4"; //// Replace the matched text in the InputText using the replacement pattern string result = MyRegex.Replace(@"Apple1231|C:\asfae\drqw\qwer|2342|1.txt",MyRegexReplace); // result 'Apple1231|C:\asfae\drqw\qwer\2342\1.txt'
Надеюсь, это поможет, С уважением, Том.
Это решение создает два новых объекта только на куче, а не на объекты, которые требуют другие решения.
static string FixString(string line)
{
if (line == null)
return string.Empty;
int firstBarPosition = line.IndexOf('|');
if (firstBarPosition == -1 || firstBarPosition + 1 == line.Length)
return line;
StringBuilder sb = new StringBuilder(line);
sb.Replace('|', '\\', firstBarPosition + 1, line.Length - (firstBarPosition + 1));
return sb.ToString();
}
Не используйте Regex.
string input = @"Apple1231|C:\asfae\drqw\qwer|2342|1.txt";
int firstPipeIndex = input.IndexOf("|");
string suffix = string.Empty;
string prefix = string.Empty;
string output = string.Empty;
if (firstPipeIndex != -1)
{
//keep the first pipe and anything before in prefix
prefix = input.Substring(0, firstPipeIndex + 1);
//all pipes in the rest of it should be slashes
suffix = input.Substring(firstPipeIndex + 1).Replace('|', '\\');
output = prefix + suffix;
}
if (!string.IsNullOrEmpty(suffix))
{
Console.WriteLine(input);
Console.WriteLine(output);
}