• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# NSRange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中NSRange的典型用法代码示例。如果您正苦于以下问题:C# NSRange类的具体用法?C# NSRange怎么用?C# NSRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NSRange类属于命名空间,在下文中一共展示了NSRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ApplyTokenAttributes

		void ApplyTokenAttributes (NSRange searchRange)
		{
			NSDictionary attributesForToken = Tokens ["DefaultTokenName"];
			int startPos = (int)searchRange.Location;

			string text = backingStore.Value.Substring ((int)searchRange.Location,(int)searchRange.Length);
			int nextSpace = text.IndexOfAny (" \n\t.".ToCharArray ());
			int lastPos = 0;
			string token;
			NSRange tokenRange;
			while (true) {
				if (nextSpace == -1)
					nextSpace = text.Length;

				token = text.Substring (lastPos, nextSpace - lastPos);
				tokenRange = new NSRange (lastPos + startPos, nextSpace - lastPos);

				if (Tokens.ContainsKey (token))
					attributesForToken = Tokens [token];
				else
					attributesForToken = Tokens ["DefaultTokenName"];

				AddAttributes (attributesForToken, tokenRange);
				if (nextSpace == text.Length)
					break;
				lastPos = nextSpace + 1;
				nextSpace = text.IndexOfAny (" \n\t.".ToCharArray (), nextSpace + 1);
			}
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:29,代码来源:InteractiveTextColoringTextStorage.cs


示例2: IsPartialStringValid

        public bool IsPartialStringValid(ref NSString partial, ref NSRange selPtr, NSString origString, ref NSRange origSel, IntPtr error)
        {
            // Zero length strings are OK
            if (partial.Length == 0) {
                return true;
            }
            string match = FirstColorKeyForPartialString(partial);
            // No color match?
            if (match == null) {
                return false;
            }

            // If no letters were added, it is a delete
            //			Console.WriteLine("orig string: {0}, partial string: {1}", origString, partial);
            if (oldColorStringLength == partial.Length) {
                oldColorStringLength--;
                selPtr.Location = partial.Length -1;
                selPtr.Length = match.Length - selPtr.Location;
                partial = (NSString)match;
                return false;
            }
            oldColorStringLength = partial.Length;
            // If the partial string is shorter than the match,
            // provide the match and set the selection
            if (match.Length != partial.Length) {
                selPtr.Location = partial.Length;
                selPtr.Length = match.Length - selPtr.Location;
                partial = (NSString)match;
                return false;
            }
            return true;
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:32,代码来源:ColorFormatter.cs


示例3: LowLevelSetAttributes

		public override void LowLevelSetAttributes (IntPtr attrs, NSRange range)
		{
			BeginEditing ();
			backingStore.LowLevelSetAttributes (attrs, range);
			Edited (NSTextStorageEditActions.Attributes, range, 0);
			EndEditing ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:7,代码来源:InteractiveTextColoringTextStorage.cs


示例4: requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler

        /// <exclude/>
        public int requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler(
			NSString stringToCheck,
			NSRange range,
			ulong checkingTypes,
			NSDictionary options,
			int tag,
			Action<int, NSArray, NSOrthography, int> callback)
        {
            RequestCheckingCallback thunk = (IntPtr context, int sequenceNumber, IntPtr resultsPtr, IntPtr orthographyPtr, int wordCount) =>
            {
                var results = NSObject.Lookup(resultsPtr).To<NSArray>();
                var orthography = NSObject.Lookup(orthographyPtr).To<NSOrthography>();
                callback(sequenceNumber, results, orthography, wordCount);
            };

            var block = new ExtendedBlock(thunk);
            int result = Call("requestCheckingOfString:range:types:options:inSpellDocumentWithTag:completionHandler:",
                stringToCheck,
                range,
                checkingTypes,
                options,
                tag,
                block).To<int>();
            GC.KeepAlive(block);

            return result;
        }
开发者ID:afrog33k,项目名称:mcocoa,代码行数:28,代码来源:NSSpellChecker.cs


示例5: ShoudChange

        public static bool ShoudChange(UITextField textField, NSRange range, string toString)
        {
            int length = getLength (textField.Text);

            if(length == 10)
            {
                if(range.Length == 0)
                    return false;
            }

            if(length == 3)
            {
                string num = formatNumber(textField.Text);
                textField.Text = string.Format ("({0}) ", num);
                if(range.Length > 0)
                    textField.Text = string.Format ("{0}", num.Substring(0, 3));
            }
            else if(length == 6)
            {
                string num = formatNumber(textField.Text);

                textField.Text = string.Format ("({0}) {1}-",num.Substring (0, 3) ,num.Substring (3));
                if(range.Length > 0)
                    textField.Text = string.Format ("({0}) {1}",num.Substring (0, 3) ,num.Substring (3));
            }

            return true;
        }
开发者ID:bholmes,项目名称:XamarinEvolve2013Project,代码行数:28,代码来源:PhoneNumberHelper.cs


示例6: ShouldChangeCharacters

		public override bool ShouldChangeCharacters(UITextField textField, NSRange theRange, String replacementString)
		{
			System.Console.WriteLine ("ShouldChangeCharacters '{0}' -> {1}, {2}, '{3}' ?", textField.Text, theRange.Location, theRange.Length, replacementString);

			// We could prevent (or warn of) nonsensical or out-of-bounds values?

			return true;
		}
开发者ID:tomgilder,项目名称:ReactiveTrader,代码行数:8,代码来源:NotionalTextFieldDelegate.cs


示例7: ShouldChangeText

		public override bool ShouldChangeText (UITextView textView, NSRange range, string text)
		{
			if (!text.Contains ("\n"))
				return true;

			textView.ResignFirstResponder ();
			return false;
		}
开发者ID:Clancey,项目名称:aws-sdk-net,代码行数:8,代码来源:SNSSampleViewController.cs


示例8: Replace

		public override void Replace (NSRange range, string newValue)
		{
			BeginEditing ();
			backingStore.Replace (range, newValue);
			Edited (NSTextStorageEditActions.Characters | NSTextStorageEditActions.Attributes, range, newValue.Length - range.Length);
			dynamicTextNeedsUpdate = true;
			EndEditing ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:8,代码来源:InteractiveTextColoringTextStorage.cs


示例9: ClearLog

		/// <summary>
		/// Clears the present logs.
		/// </summary>
		private void ClearLog()
		{
			var stor = LogField.TextStorage;
			var wholeRange = new NSRange(0, stor.Length);

			stor.BeginEditing();
			stor.DeleteRange(wholeRange);
			stor.EndEditing();
		}
开发者ID:ksasao,项目名称:Gochiusearch,代码行数:12,代码来源:MainWindowController.cs


示例10: AttributedMailText

 public NSAttributedString AttributedMailText(string text)
 {
     Random r = new Random ();
     string randomString = loremIpsum.GenerateString (10 + r.Next (0, 16));
     string str = String.Format ("{0}\n{1}", text, randomString);
     NSMutableAttributedString attrStr = new NSMutableAttributedString (str, new NSDictionary ());
     NSRange range = new NSRange (str.IndexOf ("\n"), "\n".Length);
     attrStr.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Gray, new NSRange(range.Location, str.Length - range.Location));
     return attrStr;
 }
开发者ID:sudipnath,项目名称:ios-sdk,代码行数:10,代码来源:ListViewSwipe.cs


示例11: ShouldInteractWithUrl

		bool ShouldInteractWithUrl (UITextView textView, NSUrl url, NSRange characterRange)
		{
			if (url.Host == "www.xamarin.com") {
				var webViewController = (WebViewController)Storyboard.InstantiateViewController ("WebViewController");
				PresentViewController (webViewController, true, delegate {
					webViewController.webView.LoadRequest (NSUrlRequest.FromUrl (url));
				});
				return false;
			};
			return true;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:11,代码来源:BasicInteractionViewController.cs


示例12: GetTypo

 public override string GetTypo(string txt)
 {
     #if __WATCHOS__
     return string.Empty;
     #else
     var checkRange = new NSRange (0, txt.Length);
     var typoRange = checker.RangeOfMisspelledWordInString (txt, checkRange, checkRange.Location, false, "en_US");
     if (typoRange.Length == 0)
         return String.Empty;
     return txt.Substring ((int) typoRange.Location, (int) typoRange.Length);
     #endif
 }
开发者ID:yudhitech,项目名称:xamarin-macios,代码行数:12,代码来源:iOSApiTypoTest.cs


示例13: ShouldChangeCharacters

        public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
        {
            if (string.IsNullOrEmpty(replacementString))
                return true;

            var newText = (textField.Text ?? "").Remove(range.Location, range.Length)
                             .Insert(range.Location, replacementString);
            //MvxTrace.Trace(
            //	"ShouldChangeCharacters, before: {0}, replace: {1}, newtext: {2}",
            //	this.Text, replacementString, newText);

            return IsOk(newText);
        }
开发者ID:patrykujawski,项目名称:MonoTouchMVVMCrossValidationTester,代码行数:13,代码来源:MyUIMoneyTextField.cs


示例14: ShouldChangeCharacters

            public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
            {
                var newText = textField.Text.Remove (range.Location, range.Length);
                newText = newText.Insert (range.Location, replacementString);

                if (newText.Length > 0) {
                    textField.Text = (UIDecimalField.GetAmountFromString (newText)).ToString ("N2");

                    return false;
                }

                return false;
            }
开发者ID:rajeshwarn,项目名称:GhostPractice-iPadRepo,代码行数:13,代码来源:UIDecimalField.cs


示例15: HandleCalculatePi

        /// <summary>
        /// Gets called when pressing the button to calculate PI.
        /// </summary>
        /// <param name="sender">Sender.</param>
partial         void HandleCalculatePi(UIButton sender)
        {
            this.isCalculating = !this.isCalculating;
            btnCalculate.SetTitle(this.isCalculating ? "Stop calculating" : "Start calculating", UIControlState.Normal);

            if(!this.isCalculating)
            {
                // Cancel calculation if it is currently running.
                this.cts.Cancel();
                return;
            }
            else
            {
                // Use a cancellation token to be able to stop the calculation.
                this.cts = new CancellationTokenSource();
                this.txtPi.Text = string.Empty;
            }

            // Prepare for background processing.
            int taskId = -1;

            // We are running on an extra thread here. Still, the app gets paused if it is backgrounded.
            Task.Run(() =>
            {
                // TODO: LongRunningTasks 01 - Comment back in to prevent thread from being interrupted if home button is pressed
            //				taskId = UIApplication.SharedApplication.BeginBackgroundTask(() => {
            //					Console.WriteLine("Background time expires!");
            //					this.cts.Cancel();
            //				});

                Helpers.CalcPi(pi =>
                {
                    Console.WriteLine("Background time remaining: " + Math.Round(UIApplication.SharedApplication.BackgroundTimeRemaining) + " seconds");
                    Console.WriteLine("A bit of Pi: " + pi);
                    this.InvokeOnMainThread(() =>
                    {
                        this.txtPi.Text += " " + pi;
                        var range = new NSRange(txtPi.Text.Length - 1, 1);
                        txtPi.ScrollRangeToVisible(range);
                    });
                }, this.cts.Token);

                if(taskId != -1)
                {
                    // Balanced call to BeginBackgroundTask()
                    UIApplication.SharedApplication.EndBackgroundTask(taskId);
                }
            });
        }
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:53,代码来源:LongRunningTasksViewController.cs


示例16: ShouldChangeCharacters

            public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
            {
                var text = textField.Text;
                string newText = text;
                if (range.Location >= text.Length)
                {
                    newText = text + replacementString;
                }
                else
                {
                    var substr = text.Substring(0, range.Location);
                    var finalIndex = range.Location + range.Length - 1;
                    if(finalIndex >= text.Length - 1) {
                        newText = substr + replacementString;
                    }
                    else
                    {
                        var substr2 = text.Substring(finalIndex + 1);
                        newText = substr + replacementString + substr2;
                    }
                }

                var numText = NumberFormattingHelper.StripCurrency(newText);
                if (numText.Length > _digitLimit) return false;

                string result = string.Empty;
                if (numText.Length == 0)
                {
                    result = "$0";
                }
                else
                {
                    int number;
                    if (Int32.TryParse(numText, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.CurrentCulture, out number))
                    {
                        result = string.Format("{0:C0}", number);
                    }
                }

                if (_postChangeAction != null)
                {
                    _postChangeAction(result);
                }
                
                textField.Text = result;
                
                return false;
            }
开发者ID:reactiveui-forks,项目名称:VirtualSales,代码行数:48,代码来源:TextFieldCurrencyDelegate.cs


示例17: ShouldChangeCharacters

        /// <summary>
        /// Limits the message text to MaxTextLength characters.
        /// </summary>
        public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
        {
            int limit = MaxTextLength;

            int newLength = (textField.Text.Length - (int)range.Length) + replacementString.Length;
            if (newLength <= limit)
                return true;

            int emptySpace = Math.Max(0, limit - (textField.Text.Length - (int)range.Length));
            string beforeCaret = textField.Text.Substring(0, (int)range.Location) + replacementString.Substring(0, emptySpace);
            string afterCaret = textField.Text.Substring((int)(range.Location + range.Length));

            textField.Text = beforeCaret + afterCaret;

            return false;
        }
开发者ID:pavlob0910,项目名称:my-start-stable,代码行数:19,代码来源:UITextDelegates.cs


示例18: GetSearchResultAttributedString

		public static NSMutableAttributedString GetSearchResultAttributedString (this string result, string searchString)
		{
			var attrString = new NSMutableAttributedString (result);

			attrString.AddAttributes (SearchResultStringAttributes, new NSRange (0, result.Length));

			var index = result.IndexOf (searchString, StringComparison.OrdinalIgnoreCase);

			if (index >= 0 && index + searchString.Length <= result.Length) {

				var range = new NSRange (index, searchString.Length);

				attrString.AddAttributes (SearchResultHighlightStringAttributes, range);
			}

			return attrString;
		}
开发者ID:colbylwilliams,项目名称:XWeather,代码行数:17,代码来源:AttributedStringExtensions.cs


示例19: ShouldChangeText

        /// <summary>
        /// Limits the message text to MaxTextLength characters.
        /// </summary>
        public override bool ShouldChangeText(UITextView textView, NSRange range, string text)
        {
            int limit = MaxTextLength;

            int newLength = (textView.Text.Length - (int)range.Length) + text.Length;
            if (newLength <= limit)
                return true;

            int emptySpace = Math.Max(0, limit - (textView.Text.Length - (int)range.Length));
            string beforeCaret = textView.Text.Substring(0, (int)range.Location) + text.Substring(0, emptySpace);
            string afterCaret = textView.Text.Substring((int)(range.Location + range.Length));

            textView.Text = beforeCaret + afterCaret;
            textView.SelectedRange = new NSRange(beforeCaret.Length, 0);

            return false;
        }
开发者ID:pavlob0910,项目名称:my-start-stable,代码行数:20,代码来源:UITextDelegates.cs


示例20: AllowTextChange

        protected override bool AllowTextChange(string currentText, NSRange changedRange, string replacementText, string result)
        {
            // Base method checks against the max length for us...
            if (!base.AllowTextChange (currentText, changedRange, replacementText, result))
                return false;

            // Validate that all of the characters are legal for an airport code
            for (int i = 0; i < replacementText.Length; i++) {
                if ((replacementText[i] >= 'A' && replacementText[i] <= 'Z') ||
                    (replacementText[i] >= 'a' && replacementText[i] <= 'z') ||
                    (replacementText[i] >= '0' && replacementText[i] <= '9'))
                    continue;

                return false;
            }

            return true;
        }
开发者ID:pahlot,项目名称:FlightLog,代码行数:18,代码来源:AirportEntryElement.cs



注:本文中的NSRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NSSet类代码示例发布时间:2022-05-24
下一篇:
C# NSOutlineView类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap