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

问题描述

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"

推荐答案


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.


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

11-03 07:14