PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Extracting a specific number of characters from the beginning of a string
  • Extracting a specific number of characters from the end of a string
  • Extracting a specific number of characters from the middle of a string
  • Extracting a word separated by specific characters
  • Removing leading and trailing spaces from a string
  • Replacing characters in a string
  • Checking if a string contains another string
Character string: How to extract, remove and replace words?
Extracting a specific number of characters from the beginning of a string
First syntax (recommended): Use the operators for handling strings.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = sMySourceString[[1 TO 5]]
 
// sMyResultString is set to "Hello"
Second syntax: Use the Left function.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = Left(sMySourceString, 5)
 
// sMyResultString is set to "Hello"
Extracting a specific number of characters from the end of a string
First syntax (recommended): Use the operators for handling strings.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = sMySourceString[[Length(sMySourceString) - 4 TO]]
 
// sMyResultString is set to "test"
Second syntax: Use the Right function.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = Right(sMySourceString, 4)
 
// sMyResultString is set to "test"
Extracting a specific number of characters from the middle of a string
First syntax (recommended): Use the operators for handling strings.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = sMySourceString[[7 ON 4]]
 
// sMyResultString is set to "this"
Second syntax: Use the Middle function.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = Middle(sMySourceString, 7, 4)
 
// sMyResultString is set to "this"
Extracting a word separated by specific characters
Use the ExtractString function.
sMyResultString is string
sMySourceString is string
 
sMySourceString = "Hello this is a test"
 
sMyResultString = ExtractString(sMySourceString, 2, " ")
 
// sMyResultString is set to "this"
Removing leading and trailing spaces from a string
Use the NoSpace function.
sMySourceString is string
 
sMySourceString = " Hello this is a test "
 
sMyResultString = NoSpace(sMySourceString)
 
// sMyResultString is set to "Hello this is a test"
Replacing characters in a string
Use the Replace function.
sResultString = Replace("Hello, this is a test", " ", "_")
 
// sResultString is set to : "Hello,_this_is_a_test"
Checking if a string contains another string
First syntax: to get the position of the substring, use Position.
sFullString is string = "WINDEV is a great tool"
sSubString is string = "tool"
 
nPosition is int = Position(sFullString, sSubString)
// nPosition is set to 19
Second syntax: to check whether a string contains a specific substring, use the [=] comparison operator (recommended) or the Contains function.
sFullString is string = "WINDEV is a great tool"
sSubString is string = "tool"
 
IF sFullString [=] sSubString THEN
Info("The string contains the specified substring")
END
 
// Equivalent to:
//IF Contains(sFullString, sSubString) THEN
// Info("The string contains the specified substring")
//END
Minimum version required
  • Version 19
This page is also available for…
Comments
Click [Add] to post a comment