Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > C# ปกติเวลาเราเขียนโค้ด แล้วเราสามารถ ค้นหา ในรูปแบบ regular expression ในโค้ดได้ไม๊ครับ



 

C# ปกติเวลาเราเขียนโค้ด แล้วเราสามารถ ค้นหา ในรูปแบบ regular expression ในโค้ดได้ไม๊ครับ

 



Topic : 126151



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



ปกติ C# เวลาเราเขียนๆไปถ้าเราอยากค้นหาคำก็จะใช้ Clrt+F ใช่ไม๊ครับ

ฟหกฟด

คำถามครับ

1. เราสามารถค้นหาแบบหลายๆบรรทัดได้ไม๊ (เหมือน notepad++)
2. ถ้าเราอยากจะค้นหาแบบมีเงื่อนไขเหมือน regular expression ได้ไม๊

อย่างเช่นตามโค้ดนี้ผมอยากจะค้นหา และลบ ///.*? ประมาณนี้ครับ
ซึ่งถ้าปกติผมจะทำได้แค่ ค้นหาเป็นคำๆไป
อย่างค้น
Code
/// <include file='doc\Button.uex' path='docs/doc[@for="Button"]/*' />

ค้น
Code
/// <devdoc>

ค้น
Code
/// <para>Represents a

ประมาณนี้ครับ
ซึ่งถ้าค้นแบบ regular expression ใช้แค่ ///.*?\n ก็สามารถเจอครบดังที่ว่ามา

Code (C#)
//------------------------------------------------------------------------------
// <copyright file="Button.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

/*
 */
namespace System.Windows.Forms {
    using System.Runtime.Serialization.Formatters;
    using System.Runtime.Remoting;
    using System.Runtime.InteropServices;

    using System.Diagnostics;

    using System;
    using System.Security.Permissions;
    using System.Windows.Forms.ButtonInternal;
    using System.ComponentModel.Design;
    using System.ComponentModel;
    using System.Windows.Forms.Layout;

    using System.Drawing;
    using System.Windows.Forms.Internal;
    using Microsoft.Win32;

    /// <include file='doc\Button.uex' path='docs/doc[@for="Button"]/*' />
    /// <devdoc>
    ///    <para>Represents a
    ///       Windows button.</para>
    /// </devdoc>
    [ComVisible(true),
     ClassInterface(ClassInterfaceType.AutoDispatch),
     SRDescription(SR.DescriptionButton),
     Designer("System.Windows.Forms.Design.ButtonBaseDesigner, " + AssemblyRef.SystemDesign)
    ]
    public class Button : ButtonBase, IButtonControl {

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.dialogResult"]/*' />
        /// <devdoc>
        ///     The dialog result that will be sent to the parent dialog form when
        ///     we are clicked.
        /// </devdoc>
        private DialogResult dialogResult;

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.dialogResult"]/*' />
        /// <devdoc>
        ///     For buttons whose FaltStyle = FlatStyle.Flat, this property specifies the size, in pixels  
        ///     of the border around the button.
        /// </devdoc>
        private Size systemSize = new Size(Int32.MinValue, Int32.MinValue);

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.Button"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Windows.Forms.Button'/>
        ///       class.
        ///    </para>
        /// </devdoc>
        public Button() : base() {
            // Buttons shouldn't respond to right clicks, so we need to do all our own click logic
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick,
                     false);
        }

        /// <devdoc>
        ///     Allows the control to optionally shrink when AutoSize is true.
        /// </devdoc>
        [
        SRCategory(SR.CatLayout),
        Browsable(true),
        DefaultValue(AutoSizeMode.GrowOnly),
        Localizable(true),
        SRDescription(SR.ControlAutoSizeModeDescr)
        ]
        public AutoSizeMode AutoSizeMode {
            get {
                return GetAutoSizeMode();
            }
            set {

                if (!ClientUtils.IsEnumValid(value, (int)value, (int)AutoSizeMode.GrowAndShrink, (int)AutoSizeMode.GrowOnly)){
                    throw new InvalidEnumArgumentException("value", (int)value, typeof(AutoSizeMode));
                }
                
                if (GetAutoSizeMode() != value) {                    
                    SetAutoSizeMode(value);
                    if(ParentInternal != null) {
                        // DefaultLayout does not keep anchor information until it needs to.  When
                        // AutoSize became a common property, we could no longer blindly call into
                        // DefaultLayout, so now we do a special InitLayout just for DefaultLayout.
                        if(ParentInternal.LayoutEngine == DefaultLayout.Instance) {
                            ParentInternal.LayoutEngine.InitLayout(this, BoundsSpecified.Size);
                        }
                        LayoutTransaction.DoLayout(ParentInternal, this, PropertyNames.AutoSize);
                    }
                }
            }
        }

        internal override ButtonBaseAdapter CreateFlatAdapter() {
            return new ButtonFlatAdapter(this);
        }

        internal override ButtonBaseAdapter CreatePopupAdapter() {
            return new ButtonPopupAdapter(this);
        }
            
        internal override ButtonBaseAdapter CreateStandardAdapter() {
            return new ButtonStandardAdapter(this);
        }

        internal override Size GetPreferredSizeCore(Size proposedConstraints) {
            if(FlatStyle != FlatStyle.System) {
                Size prefSize = base.GetPreferredSizeCore(proposedConstraints);
                return AutoSizeMode == AutoSizeMode.GrowAndShrink ? prefSize : LayoutUtils.UnionSizes(prefSize, Size);                
            }

            if (systemSize.Width == Int32.MinValue) {
                Size requiredSize;
                // Note: The result from the BCM_GETIDEALSIZE message isn't accurate if the font has been
                // changed, because this method is called before the font is set into the device context.
                // Commenting this line is the fix for bug VSWhidbey#228843.
                //if(UnsafeNativeMethods.SendMessage(hWnd, NativeMethods.BCM_GETIDEALSIZE, 0, size) != IntPtr.Zero) {
                //    requiredSize = size.ToSize(); ...
                requiredSize = TextRenderer.MeasureText(this.Text, this.Font);
                requiredSize = SizeFromClientSize(requiredSize);

                // This padding makes FlatStyle.System about the same size as FlatStyle.Standard
                // with an 8px font.
                requiredSize.Width += 14;
                requiredSize.Height += 9;
                systemSize = requiredSize;
            }
            Size paddedSize = systemSize + Padding.Size;            
            return AutoSizeMode == AutoSizeMode.GrowAndShrink ? paddedSize : LayoutUtils.UnionSizes(paddedSize, Size);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.CreateParams"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       This is called when creating a window. Inheriting classes can overide
        ///       this to add extra functionality, but should not forget to first call
        ///       base.CreateParams() to make sure the control continues to work
        ///       correctly.
        ///
        ///    </para>
        /// </devdoc>
        protected override CreateParams CreateParams {
            [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
            get {
                CreateParams cp = base.CreateParams;
                cp.ClassName = "BUTTON";                
                if (GetStyle(ControlStyles.UserPaint)) {
                    cp.Style |= NativeMethods.BS_OWNERDRAW;
                }
                else {
                    cp.Style |= NativeMethods.BS_PUSHBUTTON;
                    if (IsDefault) {
                        cp.Style |= NativeMethods.BS_DEFPUSHBUTTON;
                    }
                }
                return cp;
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.DialogResult"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Gets or sets a value that is returned to the
        ///       parent form when the button
        ///       is clicked.
        ///    </para>
        /// </devdoc>
        [
        SRCategory(SR.CatBehavior),
        DefaultValue(DialogResult.None),
        SRDescription(SR.ButtonDialogResultDescr)
        ]
        public virtual DialogResult DialogResult {
            get {
                return dialogResult;
            }

            set {
                if (!ClientUtils.IsEnumValid(value, (int)value, (int)DialogResult.None, (int) DialogResult.No)) {
                    throw new InvalidEnumArgumentException("value", (int)value, typeof(DialogResult));
                }
                dialogResult = value;
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.OnMouseEnter"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Raises the <see cref='System.Windows.Forms.Control.OnMouseEnter'/> event.
        ///    </para>
        /// </devdoc>
        protected override void OnMouseEnter(EventArgs e) {
            base.OnMouseEnter(e);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.OnMouseLeave"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Raises the <see cref='System.Windows.Forms.Control.OnMouseLeave'/> event.
        ///    </para>
        /// </devdoc>
        protected override void OnMouseLeave(EventArgs e) {
            base.OnMouseLeave(e);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.DoubleClick"]/*' />
        /// <internalonly/><hideinheritance/>
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced)]
        public new event EventHandler DoubleClick {
            add {
                base.DoubleClick += value;
            }
            remove {
                base.DoubleClick -= value;
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.MouseDoubleClick"]/*' />
        /// <internalonly/><hideinheritance/>
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced)]
        public new event MouseEventHandler MouseDoubleClick {
            add {
                base.MouseDoubleClick += value;
            }
            remove {
                base.MouseDoubleClick -= value;
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.NotifyDefault"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Notifies the <see cref='System.Windows.Forms.Button'/>
        ///       whether it is the default button so that it can adjust its appearance
        ///       accordingly.
        ///       
        ///    </para>
        /// </devdoc>
        public virtual void NotifyDefault(bool value) {
            if (IsDefault != value) {
                IsDefault = value;                
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.OnClick"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       This method actually raises the Click event. Inheriting classes should
        ///       override this if they wish to be notified of a Click event. (This is far
        ///       preferable to actually adding an event handler.) They should not,
        ///       however, forget to call base.onClick(e); before exiting, to ensure that
        ///       other recipients do actually get the event.
        ///
        ///    </para>
        /// </devdoc>
        protected override void OnClick(EventArgs e) {
            Form form = FindFormInternal();
            if (form != null) form.DialogResult = dialogResult;


            // accessibility stuff
            //
            AccessibilityNotifyClients(AccessibleEvents.StateChange, -1);
            AccessibilityNotifyClients(AccessibleEvents.NameChange, -1);

            base.OnClick(e);
        }

        protected override void OnFontChanged(EventArgs e) {
            systemSize = new Size(Int32.MinValue, Int32.MinValue);
            base.OnFontChanged(e);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.OnMouseUp"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Raises the <see cref='System.Windows.Forms.ButtonBase.OnMouseUp'/> event.
        ///       
        ///    </para>
        /// </devdoc>
        protected override void OnMouseUp(MouseEventArgs mevent) {
            if (mevent.Button == MouseButtons.Left && MouseIsPressed) {
                bool isMouseDown = base.MouseIsDown;

                if (GetStyle(ControlStyles.UserPaint)) {
                    //Paint in raised state...
                    ResetFlagsandPaint();
                }
                if (isMouseDown) {
                    Point pt = PointToScreen(new Point(mevent.X, mevent.Y));
                    if (UnsafeNativeMethods.WindowFromPoint(pt.X, pt.Y) == Handle && !ValidationCancelled) {
                        if (GetStyle(ControlStyles.UserPaint)) {
                            OnClick(mevent);
                        }
                        OnMouseClick(mevent);
                    }
                }
            }
            base.OnMouseUp(mevent);
        }

        protected override void OnTextChanged(EventArgs e) {
            systemSize = new Size(Int32.MinValue, Int32.MinValue);
            base.OnTextChanged(e);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.PerformClick"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Generates a <see cref='System.Windows.Forms.Control.Click'/> event for a
        ///       button.
        ///    </para>
        /// </devdoc>
        public void PerformClick() {
            if (CanSelect) {
                bool validatedControlAllowsFocusChange;
                bool validate = ValidateActiveControl(out validatedControlAllowsFocusChange);
                if (!ValidationCancelled && (validate || validatedControlAllowsFocusChange))
                {
                    //Paint in raised state...
                    //
                    ResetFlagsandPaint();
                    OnClick(EventArgs.Empty);
                }
            }
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.ProcessMnemonic"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Lets a control process mnmemonic characters. Inheriting classes can
        ///       override this to add extra functionality, but should not forget to call
        ///       base.ProcessMnemonic(charCode); to ensure basic functionality
        ///       remains unchanged.
        ///
        ///    </para>
        /// </devdoc>
        [UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
        protected internal override bool ProcessMnemonic(char charCode) {
            if (UseMnemonic && CanProcessMnemonic() && IsMnemonic(charCode, Text)) {
                PerformClick();
                return true;
            }
            return base.ProcessMnemonic(charCode);
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.ToString"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Provides some interesting information for the Button control in
        ///       String form.
        ///    </para>
        /// </devdoc>
        public override string ToString() {

            string s = base.ToString();
            return s + ", Text: " + Text;
        }

        /// <include file='doc\Button.uex' path='docs/doc[@for="Button.WndProc"]/*' />
        /// <devdoc>
        ///     The button's window procedure.  Inheriting classes can override this
        ///     to add extra functionality, but should not forget to call
        ///     base.wndProc(m); to ensure the button continues to function properly.
        /// </devdoc>
        /// <internalonly/>
        [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
        protected override void WndProc(ref Message m) {
            switch (m.Msg) {
                case NativeMethods.WM_REFLECT + NativeMethods.WM_COMMAND:
                    if (NativeMethods.Util.HIWORD(m.WParam) == NativeMethods.BN_CLICKED) {
                        Debug.Assert(!GetStyle(ControlStyles.UserPaint), "Shouldn't get BN_CLICKED when UserPaint");
                        if (!ValidationCancelled) {
                            OnClick(EventArgs.Empty);
                        }                        
                    }
                    break;
                case NativeMethods.WM_ERASEBKGND:
                    DefWndProc(ref m);
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
    }
}







Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-01-25 15:38:16 By : lamaka.tor View : 1220 Reply : 1
 

 

No. 1



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

https://docs.microsoft.com/en-us/visualstudio/ide/using-regular-expressions-in-visual-studio?view=vs-2019






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-07-09 12:28:33 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# ปกติเวลาเราเขียนโค้ด แล้วเราสามารถ ค้นหา ในรูปแบบ regular expression ในโค้ดได้ไม๊ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่