要将句子转换为单词数组,您可以使用编程语言中的字符串分割函数。以下是几种常见编程语言的示例:
- Python:sentence = "This is a sample sentence."
words = sentence.split()
print(words)
- JavaScript:const sentence = "This is a sample sentence.";
const words = sentence.split(" ");
console.log(words);
- Java:String sentence = "This is a sample sentence.";
String[] words = sentence.split(" ");
System.out.println(Arrays.toString(words));
- C#:string sentence = "This is a sample sentence.";
string[] words = sentence.Split(' ');
Console.WriteLine(string.Join(", ", words));
这些示例中的代码将句子拆分成单词数组。请注意,这些示例仅适用于以空格分隔的单词。根据您的需求,您可能需要处理其他分隔符,例如标点符号。