English 中文(简体)
你们如何分裂
原标题:How would you split by if String.Split(String[]) did not exist?

利用“NET MicroFramework”,这是C#的实际削减版本。 例如,System.String几乎没有我们多年来所享受的任何货物。

I need to split a text document into lines, which means splitting by . However, String.Split only provides a split by char, not by string.

我怎么能以高效的方式将文件分成几条线(例如,在狗中,每条果园都不会 lo)?

P.S. System.String is also missing a Replace method, so that won t work.
P.P.S. Regex is not part of the MicroFramework either.

最佳回答

你可以做些什么。

string[] lines = doc.Split( 
 );
for (int i = 0; i < lines.Length; i+= 1)
   lines[i] = lines[i].Trim();

假设微额基金支持Trim()。 Trim()将拆除所有可能有用的白色空间。 否则,TrimEnd( )

问题回答

我将跨越该文件中的每一节点,因为这显然是必要的。 你们如何看待<代码>。 Split work? 然而,我只想一度打上每个特性。

保留迄今发现的座标清单。 使用<条码>IndexOf,在座标上多次通过(即以前的对称+2)。

我怎么能以高效的方式将文件分成几条线(例如,在狗中,每条果园都不会 lo)?

您如何考虑在<条码>上安装<>条码>。

只是作为延伸方法加以补充。

什么是:

string path = "yourfile.txt";
string[] lines = File.ReadAllLines(path);

string content = File.ReadAllText(path);
string[] lines = content.Split(
    Environment.NewLine.ToCharArray(),
    StringSplitOptions.RemoveEmptyEntries);

阅读:。 NET Micro Framework 3.0,本守则可发挥作用:

string line = String.Empty;
StreamReader reader = new StreamReader(path);
while ((line = reader.ReadLine()) != null)
{
    // do stuff
}

在某些情况下,这可能有助于:

StreamReader reader = new StreamReader(file);    
string _Line = reader.ReadToEnd();
string IntMediateLine = string.Empty;
IntMediateLine = _Line.Replace("entersign", "");
string[] ArrayLineSpliter = IntMediateLine.Split( any specail chaarater );

如果你喜欢MicroFramework 兼容可操作整个的特性说明/strong>的分离功能,那么,这里就象使用Sting SplitOptions的常规框架版本那样,照相。 无:

    private static string[] Split(string s, string delim)
    {
        if (s == null) throw new NullReferenceException();

        // Declarations
        var strings = new ArrayList();
        var start = 0;

        // Tokenize
        if (delim != null && delim != "")
        {
            int i;
            while ((i = s.IndexOf(delim, start)) != -1)
            {
                strings.Add(s.Substring(start, i - start));
                start = i + delim.Length;
            }
        }

        // Append left over
        strings.Add(s.Substring(start));

        return (string[]) strings.ToArray(typeof(string));
    }

你可以把你的扼杀与扼杀分开。

String.Split(new string[] { "
" }, StringSplitOptions.None);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...