Форум breadcrumbs - Вы здесь:ФорумПервая помощь: Подскажите / помогите / спасите / сохранитеУдалить повторяющиеся группы симв …
Вы должны войти, чтобы создавать сообщения и темы.
Удалить повторяющиеся группы символов в строке
Kirill@xfg
1 Сообщение
#1 · 25.03.2024, 14:47
Цитата: Kirill от 25.03.2024, 14:47Здравствуйте!
Не могу разобраться как можно сделать такую строку "Исходное" => 8509.АРЩ, 8509.5010.4, 8406.5010.4, 8406.У4905, 8406.У4904, 8406.5010.3, 8509.5010.3, 8509.2Д19 привести к такой АРЩ, 5010.4, У4905, У4904, 5010.3, 2Д19. Удалить дубликаты и что бы такая получилась.
Наработки
using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.TextFormatting; using Microsoft.Office.Interop.Word; using Teigha.Runtime; namespace ReplaceCSharp { public class Class1 { public static void Main() { Microsoft.Office.Interop.Word._Application app; Microsoft.Office.Interop.Word._Document doc; //Application app = new Application(); //Document document = new Document(); app = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); doc = app.Documents.Application.ActiveDocument; Selection s = doc.Application.Selection; var words = s.Text.GroupBy(x => x).Where(g => g.Count() > 1) .ToDictionary(x => x.Key, x => x.Count()); //s.Text.Split().Select(x => x.ToLower()).OrderBy(x => x).Distinct(); var text = String.Join(",", words); //words.Select(x => text); //s.Text.Distinct().ToArray(); //s.Text.GetType().ToString(); //GetSortedWords(text); s.Text = text; } //public static string[] GetSortedWords(params string[] textLines) //{ //return textLines.SelectMany(x => Regex.Split(x, @"\W"))//разбиваем текст на слова // //.Select(x => x.ToLower()) //изменяем регистр слов на нижний // //.Where(i => i != "") //ищем пустые строки // //.OrderBy(x => x)//производим сортировку // //.Distinct().ToArray(); //производим удаление всех дубликатов и все это упаковываем в массив string //} } }
Здравствуйте!
Не могу разобраться как можно сделать такую строку "Исходное" => 8509.АРЩ, 8509.5010.4, 8406.5010.4, 8406.У4905, 8406.У4904, 8406.5010.3, 8509.5010.3, 8509.2Д19 привести к такой АРЩ, 5010.4, У4905, У4904, 5010.3, 2Д19. Удалить дубликаты и что бы такая получилась.
Наработки
Скопировано
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.TextFormatting;
using Microsoft.Office.Interop.Word;
using Teigha.Runtime;
namespace ReplaceCSharp
{
public class Class1
{
public static void Main()
{
Microsoft.Office.Interop.Word._Application app;
Microsoft.Office.Interop.Word._Document doc;
//Application app = new Application();
//Document document = new Document();
app = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
doc = app.Documents.Application.ActiveDocument;
Selection s = doc.Application.Selection;
var words = s.Text.GroupBy(x => x).Where(g => g.Count() > 1)
.ToDictionary(x => x.Key, x => x.Count());
//s.Text.Split().Select(x => x.ToLower()).OrderBy(x => x).Distinct();
var text = String.Join(",", words);
//words.Select(x => text);
//s.Text.Distinct().ToArray();
//s.Text.GetType().ToString();
//GetSortedWords(text);
s.Text = text;
}
//public static string[] GetSortedWords(params string[] textLines)
//{
//return textLines.SelectMany(x => Regex.Split(x, @"\W"))//разбиваем текст на слова
// //.Select(x => x.ToLower()) //изменяем регистр слов на нижний
// //.Where(i => i != "") //ищем пустые строки
// //.OrderBy(x => x)//производим сортировку
// //.Distinct().ToArray(); //производим удаление всех дубликатов и все это упаковываем в массив string
//}
}
}
Голосуйте - палец вниз.0Голосуйте - палец вверх.0