我有一个很好的正则表达式来替换字符串中的重复字符.但是现在我还需要替换重复的单词,三个或更多的单词将被两个单词替换.
喜欢
bye! bye! bye!
Run Code Online (Sandbox Code Playgroud)
应该成为
bye! bye!
Run Code Online (Sandbox Code Playgroud)
我的代码到目前为止:
def replaceThreeOrMoreCharachetrsWithTwoCharacters(string):
# pattern to look for three or more repetitions of any character, including newlines.
pattern = re.compile(r"(.)\1{2,}", re.DOTALL)
return pattern.sub(r"\1\1", string)
Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制自己的工具提示。但我无法摆脱标准阴影。
它是一个标准的WinForm应用程序,有很多表单。因此是
Application.EnableVisualStyles();
Run Code Online (Sandbox Code Playgroud)
当应用程序启动时调用并需要。如果我注释掉这一行,它就会起作用。我在下面制作了一个最小的 WinForm 应用程序。如果EnableVisualStyles被注释掉,它只绘制一个红色矩形。当我取消注释时,它会绘制一个带有阴影的红色矩形。
有谁知道如何解决这个问题?如何拥有 Application.EnableVisualStyles(),并拥有 100% OwnerDrawn 的工具提示,而没有任何标准阴影?
最小的 WinForm 应用程序在这里:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ToolTipExample
{
public class MainForm : Form
{
[STAThread]
static void Main()
{
// Comment out below line and it works.
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
private ToolTip toolTip;
private Button button;
public MainForm()
{
toolTip = new ToolTip();
toolTip.OwnerDraw = true;
toolTip.Draw += new DrawToolTipEventHandler(toolTip1_Draw);
toolTip.Popup += new PopupEventHandler(toolTip1_Popup);
button = new Button();
button.Location = new Point(25, 25);
button.Text …Run Code Online (Sandbox Code Playgroud)