Search
 
SCRIPT & CODE EXAMPLE
 

C

extract substring after certain character in flutter

String s = "one.two";

//Removes everything after first '.'
String result = s.substring(0, s.indexOf('.'));
print(result);
---------------------------------------------
to keep it even simpeler, with 's' as the initial string one.two then 
s.substring(0, s.indexOf('.')) produces: one 
and s.substring(s.indexOf('.') + 1) produces: two
---------------------------------------------

In case there are more than one '.' in the String it will use the first occurrance. 
If you need to use the last one (to get rid of a file extension, for example) change 
indexOf to lastIndexOf. If you are unsure there is at least one occurrance, you 
should also add some validation to avoid triggering an exception.

String s = "one.two.three";

//Remove everything after last '.'
var pos = s.lastIndexOf('.');
String result = (pos != -1)? s.substring(0, pos): s;
print(result);
Comment

PREVIOUS NEXT
Code Example
C :: c float 
C :: how to read keyboard input in C 
C :: c in array 
C :: c sleep milliseconds 
C :: sleep function in c 
C :: initializa 2d array c 
C :: malloc c include 
C :: remove string from string c 
C :: C first digit of integer 
C :: c check first character of string 
C :: bootstrap form 
C :: typedef vs #define 
C :: printing out an array in c from user input 
C :: bubble sort in c 
C :: how to get file size in c 
C :: sh: tailwindcss: command not found 
C :: C strlen implementation 
C :: 2d array in c 
C :: how to insert elements in and array and print it in c 
C :: input value from terminal to c 
C :: Relational Operator in C language 
C :: C special character display 
C :: loops questions on c 
C :: bp result system 
C :: how to declare an array of n numbers in c 
C :: arduino vscode upload choosing sketch 
C :: C Character l/O 
C :: C (GEM) 
C :: code to reverse the words in a sentnce 
C :: fraction sum c 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =