PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Extracting a specific number of characters at the beginning of a string
  • Extracting a specific number of characters at the end of a string
  • Extracting a specific number of characters in the middle of a string
  • Extracting a word separated by specific characters
  • Deleting spaces at the beginning and end of a string
  • Replacing characters in a string
  • Finding out whether a sub-string is included in another string
Character string: How to extract, delete, replace words?
Extracting a specific number of characters at 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 Left.
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 at 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 Right.
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 in 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 Middle.
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 ExtractString.
sMyResultString is string
sMySourceString is string

sMySourceString = "Hello this is a test"

sMyResultString = ExtractString(sMySourceString, 2, " ")

// sMyResultString is set to "this"
Deleting spaces at the beginning and end of a string
Use NoSpace.
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 Replace.
sResultString = Replace("Hello, this is a test", " ", "_")

// sResultString is set to : "Hello,_this_is_a_test"
Finding out whether a sub-string is included in another string
First syntax: if the position of the sub-string must be retrieved, 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: if you just want to find out whether the sub-string is found, use the comparison operator[=] (recommended) or Contains.
sFullString is string = "WINDEV is a great tool"
sSubString is string = "tool"

IF sFullString [=] sSubString THEN
Info("The sub-string is found in the full string")
END

// Equivalent to:
//IF Contains(sFullString, sSubString) THEN
// Info("The sub-string is found in the full string")
//END
Minimum required version
  • Version 19
This page is also available for…
Comments
Click [Add] to post a comment