如何拆分“Enterkey”一个字符串/ - 数组 [英] How to split out a "Enterkey" of a string /- array

查看:60
本文介绍了如何拆分“Enterkey”一个字符串/ - 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,


我有问题。我想拆分一个字符串,比如

Hello Guys,

welkome到我家。


Probem是,我想得到这个字符串并将其保存在一个数组中。但是,我希望第一行在索引0中,第二行在索引2中。所以我需要.Split它。


但是我在()中写了什么?


感谢您的答案

___________________________________________

抱歉,我的英语非常糟糕。 ^^

解决方案

C#代码中的输入或返回字符通常由''\ n''字符表示,但有时字符串为\\ \\r\\\
" (也包含在Environment.NewLine中)。你可以通过很多方法来解决这个问题,但你应该首先看一下字符串类。


如果查看Split,可以看到它需要一个字符或字符串并返回一个字符串数组,与您正在寻找的非常相似。现在轻微的问题是你已经声明你想要你的数组的索引0中的第一行,以及索引2中的第二行,这意味着你想要索引1为空?如果这是正确的而不是拼写错误,你可能只需要运行拆分,然后将字符串复制到适当的位置。


解决不确定性无论是否使用Environment.NewLine或只是''\ n'',你可以做一个检查...类似于:

展开 | 选择 | Wrap | 行号


感谢您的回答。你的英语很难理解^^。在任何情况下,我用''\\​​\\ n''进行了测试,但它给出了错误。


i尝试解释我的意思:

Sting text是一个多行文本框。

例如:

Hello guys

你好吗?


现在我想将行保存在同一个字符串数组中但在另一个索引中。

在这个例子中textarray [0] = Hello guys"

textarray [1] ="你好吗?"

怎么能我解决了这个问题?


我猜你的英语不是你的第一语言,因为你的第一篇文章和随后的评论,所以让我们尝试减少语言障碍。你能复制/粘贴你拥有的代码及其产生的错误吗?


我想看看你尝试了什么,然后我可以帮助你理解你得到的错误。

Hey,

I have a problem. I want to split a string like
"Hello Guys,
welkome to my home".

The Probem is, that i want to get this string and save it in a array. But, i want that the first line is in the index 0 and the second line in index 2. So i need to .Split it.

But what do i write in the ( )?

Thanks for answers
___________________________________________
Sorry for my very bad english. ^^

解决方案

An enter, or return, character in C# code is represented usually by a ''\n'' character, though sometimes the string "\r\n" (contained in Environment.NewLine) is used as well. There''s a lot of ways you can approach this but you should probably start by looking at the methods available on the String class.

If you look at Split, you can see that it takes a character or string and returns an array of strings, which is very similar to what you''re looking for. Now the slight catch here is that you''ve stated you want the first line in index 0 of your array, and the second line in index 2, which means you want index 1 empty? If that''s correct and not a typo, you''ll likely just have to run the split, then copy the strings into the appropriate place later.

To resolve the uncertainty as to whether or not an Environment.NewLine is used or just ''\n'', you can probably do a check... something like:

Expand|Select|Wrap|Line Numbers


thanks for your answer. Your english is hard to understand ^^. In any case, I tested it with the ''\n'' but it gives errors.

i try to explane what i mean:
Sting text is a multiline textbox.
e.g.:
"Hello guys
how are you?"

now i want to save the lines in the same string array but in another index.
in this example textarray[0] = Hello guys"
textarray [1] = "How are you?"
how can i solve this problem?


I''m guessing that English isn''t your first language because of your first post and subsequent comment, so lets try reducing the language barrier. Can you copy/paste the code you have and the error it generated?

I''d like to see what you tried and then perhaps I can help you understand the error you got.


这篇关于如何拆分“Enterkey”一个字符串/ - 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆