如何在字符串空间内找不到字符串不敏感?

时间:2017-12-23 16:58:20

标签: python string python-3.x if-statement contains

例如,如果字符串包含:

public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, IApplicationLifetime applicationLifetime)
{
    var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
    {
        var host = sbc.Host(new Uri("rabbitmq://localhost"), h =>
        {
            h.Username("guest");
            h.Password("guest");
        });

        sbc.ReceiveEndpoint(host, Configuration["QueueName"], e =>
        {
            e.LoadFrom(serviceProvider);
        });
    });

    // start/stop the bus with the web application
    applicationLifetime.ApplicationStarted.Register(bus.Start);
    applicationLifetime.ApplicationStopped.Register(bus.Stop);
}

我如何检查它是否包含"月亮"?

我目前所做的是(但不起作用):

odfsdlkfn dskfThe Moonaosjfsl dflkfn

有没有这样做?

谢谢!

2 个答案:

答案 0 :(得分:1)

简单:

string = 'odfsdlkfn dskfThe Moonaosjfsl dflkfn'
if 'The Moon' in string:
    dosomething

答案 1 :(得分:0)

你可以使用正则表达式:

import re
text = "odfsdlkfn dskfThe Moonaosjfsl dflkfn"
if re.find("The Moon", text):
    ...

在这种情况下,如果需要,你可以使用re(pattern, text, re.IGNORECASE)进行套管。