如何在matlab中删除字符串中的重复单词

时间:2016-05-13 13:17:23

标签: string matlab

考虑我有这个字符串

[Serializable]
[LuisModel("xxxxx", "xxxx")]
public class BookFlightDialog : LuisDialog<BookFlightForm>
{
    private readonly BuildFormDelegate<BookFlightForm> BuildForm;

    internal BookFlightDialog(BuildFormDelegate<BookFlightForm> buildForm)
    {
        BuildForm = buildForm;
    }

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {
        await context.PostAsync("I'm sorry. I didn't understand you.");

        context.Wait(MessageReceived);
    }

    [LuisIntent("BookAFlight")]
    public async Task BookAFlight(IDialogContext context, LuisResult result)
    {
        var form = new BookFlightForm();
       // var entities = new List<EntityRecommendation>(result.Entities);

        var locations = result.Entities.Where(e => e.Type.Equals("builtin.geography") || e.Type.Equals("builtin.geography.city")).OrderBy(e => e.StartIndex);

        if (locations.Any())
        {
            form.LocationFrom = locations.First().Name;

            if (locations.Count() == 2)
            {
                form.LocationTo = locations.Skip(1).First().Name;
            }
        }

        var date = result.Entities.FirstOrDefault(e => e.Type == "builtin.datetime.date");
        if (date != null) form.DepartureDate = DateTime.Parse(date.Name);

        var formDialog = new FormDialog<BookFlightForm>(form, BuildForm, FormOptions.PromptInStart);

        context.Call(formDialog, OnComplete);
    }

    private async Task OnComplete(IDialogContext context, IAwaitable<BookFlightForm> result)
    {
        BookFlightForm booking;
        try
        {
            booking = await result;
        }
        catch (OperationCanceledException)
        {
            await context.PostAsync("Ok, see you later.");
            return;
        }

        if (booking != null)
        {
            var service = new SkyScannerService();
            var possibilities = await service.Search(booking);

            await context.PostAsync(possibilities);
        }
        else
        {
            await context.PostAsync("Form returned empty response!");
        }

        context.Wait(MessageReceived);
    }
}

我希望处理此字符串以获取

a='flexray_datain_flexray_sensors'

事情是,这可以用于任何重复的单词,而不仅仅是matlab中的 flexray 。如果我已经知道这个词是什么,那么它很容易

我试过了:

a='flexray_datain_sensors'

然后使用unique或something处理此单元格(部分)并删除重复的单词。但我需要一个更好的答案。

1 个答案:

答案 0 :(得分:3)

这对你有用吗?

strjoin(unique(strsplit(a,'_'),'stable'),'_')