当前位置:编程学习 > C#/ASP.NET >>

将字符串根据空格转化为数组

字符串ddd = “0 50 60 70 80 90 100 75 85 ”
变成
a[0] = '0'
a[1] = '50'
a[2] = '60'
a[3] = '70'
.....
--------------------编程问答--------------------             string ddd = “0 50 60 70 80 90 100 75 85 ” 
            string[] str = ddd.Split("".ToCharArray());
            foreach(string subStr in str)
            {
                Console.WriteLine(subStr);
            }
            for (int i = 0; i < str.Length;i++ )
            {
                Console.WriteLine(str[i]);
            }
        } --------------------编程问答--------------------
引用 1 楼 gxd0123net 的回复:
            string ddd = “0 50 60 70 80 90 100 75 85 ”  
             string[] str = ddd.Split("".ToCharArray()); 
             foreach(string subStr in str) 
             { 
                 Console.WriteLine(subStr); 
             } 
             for (int i = 0; i  < str.Length;i++ ) 
             { 
                 Console.WriteLine(str[i]); 
             } 
         }


--------------------编程问答-------------------- string str= “10 30 50 70”  
  string[] str1 = ddd.Split(""); 
--------------------编程问答-------------------- split字符分割返回数组,遍历下九可以了 --------------------编程问答-------------------- 这个貌似可以不用在这里问吧。。。 --------------------编程问答--------------------
引用 4 楼 grzx2210 的回复:
split字符分割返回数组,遍历下九可以了

强大!我试过这个最优! --------------------编程问答-------------------- split字符分割返回数组

  using System;
  using System.Collections.Generic;
  using System.Text;


  public class SplitTest
     {
      public static void Main()
      {
          string words = "this is a list of words, with: a bit of punctuation.";
          string[] split = words.Split(new Char[] { ' ', ',', '.', ':' });
          foreach (string s in split)
          {
            if (s.Trim() != "")
                Console.WriteLine(s);
           }
      }
   } --------------------编程问答-------------------- string ddd= “10 30 50 70” 
  string[] str1 = ddd.Split(" ");  --------------------编程问答-------------------- string[] a=ddd.Split(" "); --------------------编程问答--------------------
ddd.split(" "); --------------------编程问答-------------------- 以上全对 --------------------编程问答-------------------- 和java的一样也
补充:.NET技术 ,  其他语言
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,