任何人都可以编译正确的代码。我是编码新手 [英] Can anyone compile for the correct code. I am very new in coding

查看:81
本文介绍了任何人都可以编译正确的代码。我是编码新手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void Main(string[] args)
{
	// The files used in this example are created in the topic
	// How to: Write to a Text File. You can change the path and
	// file name to substitute text files of your own.

	// Example #1
	// Read the file as one string.
	string text = System.IO.File.ReadAllText(@"C:\Users\VIJAY SOITAAB\Desktop\C#\Text folder\WriteText.txt");

	// Display the file contents to the console. Variable text is a string.
	//Console.WriteLine("Contents of WriteText.txt = {0}", text);
	//char c = (char)127; // last ascii character
	char c = 'A';

	if ((int)c == 127) // check for last ascii character
	{
		Console.WriteLine("Done");
	}
	else
	{
		char result = GetNextChar(c);

		//Console.WriteLine("I have " + c + " it should give " + result);
		Console.WriteLine("Contents of WriteText.txt = {0}", text);
		//System.out.println(c);

		//Console.WriteLine("The age is " + age);
	   // Console.ReadKey();
	}

}

private static char GetNextChar(char c)
{
	// convert char to ascii
	int ascii = (int)c;
	// get the next ascii
	int nextAscii = ascii + 1;
	// convert ascii to char
}





我尝试了什么:



读取文本文件并尝试输出下一个字符的字符

示例:



你好世界



必须输出为



ifmmp xpsme



What I have tried:

Reading a text file and trying to output the Characters for the next characters
Example:

"hello world"

must output as

"ifmmp xpsme"

推荐答案

这是你的作业,所以你没有代码!



但这并不复杂:

你需要的第一件事就是循环查看文件所保存的字符串中的每个字符。 (提示:请查看文档中的 foreach 。)然后,您可以处理字符串中的每个字符。



注意:我会仔细检查问题并确保每个字符都要更改:如果你更改其中一些字符,你会得到一些非常奇怪的结果 - 文件中的每一行文字都以换行结束,而你可能不想改变它!
This is your homework, so you get no code!

But this isn't complicated:
The first thing you will need is a loop to look at each character in the string the file held. (HINT: Look at foreach in the documentation.) Then you can work with each character in the string.

Note: I'd double check the question and make sure that every character is to be changed: if you change some of them, you will get some very odd results - each line of text in the file ends with a newline, and you probably don't want to change that!


这个怎么样:



How about this:

public static void Main(string[] args)
{
  string text = System.IO.File.ReadAllText(@"C:\Users\VIJAY SOITAAB\Desktop\C#\Text folder\WriteText.txt");

  foreach (var c in text) {
    if (char.IsLetter(c)) {
      Console.Write((char)(c + 1));
    } else {
      Console.Write(c);
    }
  }





IsLetter()检查用于排除空间也改变了。



The IsLetter() check is there to exclude the space from being changed as well.


这篇关于任何人都可以编译正确的代码。我是编码新手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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