strings.Fields() Function in Golang With Examples Last Updated : 19 Apr, 2020 Comments Improve Suggest changes Like Article Like Report strings.Fields() Function in Golang is used to splits the given string around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of str or an empty slice if str contains only white space. Syntax: func Fields(str string) []string Returns: A slice of substrings of str or an empty slice if str contains only white space. Example 1: C // Golang program to illustrate the // strings.Fields() Function package main import ( "fmt" "strings" ) func main() { // String s is split on the basis of white spaces // and store in a string array s := "GeeksforGeeks is a computer science portal !" v := strings.Fields(s) fmt.Println(v) // Another example by passing the string as argument // directly to the Fields() function v = strings.Fields("I am a software developer, I love coding") fmt.Println(v) } Output: [GeeksforGeeks is a computer science portal !] [I am a software developer, I love coding] Example 2: C // Golang program to illustrate the // strings.Fields() Function package main import ( "fmt" "strings" ) func main() { // Fields function also splits the string // on the basis of white spaces and tabs s := strings.Fields(" I \t love \n to \n code \n all \t day.") fmt.Println(s) // Splits into 5 words which have // newline character in between s = strings.Fields("I\nam\nlearning\nGo\nlanguage") fmt.Println(s) } Output: [I love to code all day.] [I am learning Go language] Comment More infoAdvertise with us Next Article Must Do Coding Questions - Topic-wise V vanigupta20024 Follow Improve Article Tags : Go Language Golang-String Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like