<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C#從字符串中提取固定步長的子字符串

      C#的Substring方法只能提取固定長度的子字符串,不能直接提取固定步長的子字符串。因此,我們需要自己編寫一個方法來實現這個功能。

      這個方法可以用于從字符串中提取固定步長的子字符串。例如,如果 str 是 "HelloWorld",finger 是 2,step 是 3,那么返回的數組將是 ["llo", "rld"]。

      注意:
      最后的子字符串可能小于步長,這里是保留存入字符串數組中的。
      例如,如果 str 是 "HelloWorld",finger 是 0,step 是 3,那么返回的數組將是 ["He", "loW","orl","d"]。

      使用重載方法時,可以指定起始位置和結束位置來提取子字符串。例如,如果 str 是 "HelloWorld",startIndex 是 2,endIndex 是 9,step 是 3,那么返回的數組將是 ["llo", "rld"]。

      這個方法非常靈活,可以根據需要提取字符串的任意部分。例如,如果 str 是 "HelloWorld",startIndex 是 1,endIndex 是 8,step 是 2,那么返回的數組將是 ["el", "oW", "r"]。

      使用該方法時,需要注意以下幾點:

      • 步長必須是正數,否則會拋出異常。
      • 結束位置不能超過字符串的長度,否則會拋出異常。
      • 起始位置必須小于結束位置,否則返回一個空數組。
      // 定義一個靜態方法,接受一個字符串 str、一個整數 finger 和一個整數 step 作為參數
      public static string[] StepSubstring(string str, int finger, int step)
      {  
          // 計算從 finger 到字符串末尾的長度
          int len = str.Length - finger;  
      
          // 計算要提取的子字符串的數量。如果 len 可以被 step 整除,則子字符串的數量是 len / step,否則是 len / step + 1。
          int length = len % step == 0 ? len / step : len / step + 1;  
      
          // 創建一個字符串數組,用于存儲提取的子字符串
          string[] substrings = new string[length];  
      
          // 使用 for 循環來提取子字符串并存儲在 substrings 數組中
          for (int i = 0; i < length; i++)  
          {  
              // 計算當前子字符串的長度。如果 i 小于 length - 1 并且 finger + step 不超過字符串的長度,則子字符串的長度為 step,否則為 str.Length - finger。
              int substringLength = (i < length - 1 && finger + step <= str.Length) ? step : str.Length - finger;  
      
              // 使用 Substring 方法提取子字符串,并將其存儲在 substrings 數組中的當前位置
              substrings[i] = str.Substring(finger, substringLength);  
      
              // 更新 finger 的值,以便下次迭代時提取下一個子字符串
              finger += step;  
          }  
      
          // 返回存儲了所有提取的子字符串的數組
          return substrings;  
      }
      
      // 可以指定結束位置的重載方法
      public static string[] StepSubstring(string str, int startIndex, int endIndex, int step)
      {
          // 檢查步長是否為正數
          if (step <= 0)
              throw new ArgumentException("Step must be a positive integer.", nameof(step));
      
          // 檢查結束位置是否超過字符串長度
          if (endIndex > str.Length - 1)
              throw new ArgumentException("EndIndex cannot exceed the string length.", nameof(endIndex));
      
          // 檢查起始位置是否大于等于結束位置
          if (startIndex >= endIndex)
              return Array.Empty<string>();
      
          // 計算要提取的子字符串的數量。如果 len 可以被 step 整除,則子字符串的數量是 len / step,否則是 len / step + 1。
          int len = endIndex - startIndex;
          int length = len % step == 0 ? len / step : len / step + 1;
      
          // 創建一個字符串數組,用于存儲提取的子字符串
          string[] substrings = new string[length];
      
          // 使用 for 循環來提取子字符串并存儲在 substrings 數組中
          for (int i = 0; i < length; i++)
          {
              // 計算當前子字符串的長度。如果 i 小于 length - 1 并且 startIndex + step 不超過 endIndex,則子字符串的長度為 step,否則為 endIndex - startIndex。
              int substringLength = (i < length - 1 && startIndex + step <= endIndex) ? step : endIndex - startIndex;
      
              // 使用 Substring 方法提取子字符串,并將其存儲在 substrings 數組中的當前位置
              substrings[i] = str.Substring(startIndex, substringLength);
      
              // 更新 startIndex 的值,以便下次迭代時提取下一個子字符串
              startIndex += step;
          }
      
          // 返回存儲了所有提取的子字符串的數組
          return substrings;
      }
      
      posted on 2023-12-07 17:30  瞬間moment  閱讀(251)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 亚洲中文字幕人成影院| 加勒比亚洲天堂午夜中文| 18禁超污无遮挡无码网址| 强奷漂亮少妇高潮伦理| 亚洲精品国产suv一区88| 亚洲 日韩 国产 制服 在线| 国产欧美日韩免费看AⅤ视频| 日韩av在线不卡一区二区三区| 日韩人妻系列无码专区| 国产中文字幕在线一区| 中文字幕在线精品国产| 乱色熟女综合一区二区三区| 亚洲国产成人午夜在线一区| 久久婷婷综合色一区二区| 久久婷婷五月综合色欧美| 韩国精品福利视频一区二区| 日本福利一区二区精品| 99精品伊人久久久大香线蕉| 99久久激情国产精品| 熟女精品视频一区二区三区| 久久午夜无码鲁丝片直播午夜精品 | 国产精品国产亚洲看不卡| 99国产精品国产精品久久| 97se综合| 麻豆一区二区三区精品视频| 久久夜色撩人国产综合av| 免费国产又色又爽又黄的网站| 99久久久无码国产麻豆| 郧西县| 久久精品国产福利一区二区| 99久久亚洲综合精品成人网| 欧美亚洲综合成人A∨在线| 边添小泬边狠狠躁视频| 伊在人间香蕉最新视频| 亚洲成人av一区二区| 精品无码成人片一区二区| 亚洲精选av一区二区| 巨爆乳中文字幕爆乳区| 免费国产一区二区不卡| 亚洲国产成人精品区综合| 国产国拍精品av在线观看|