add extractTextBetweenString
This commit is contained in:
24
src/util.jl
24
src/util.jl
@@ -6,6 +6,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep
|
||||
dfToString, dataframe_to_json_list, dictToString, dictToString_noKey,
|
||||
dictToString_numbering, extract_triple_backtick_text,
|
||||
countGivenWords, remove_french_accents, detect_keyword, extractTextBetweenCharacter,
|
||||
extractTextBetweenString,
|
||||
convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex
|
||||
|
||||
using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames
|
||||
@@ -1070,6 +1071,29 @@ function extractTextBetweenCharacter(text::String, startchar::Char, endchar::Cha
|
||||
end
|
||||
|
||||
|
||||
function extractTextBetweenString(text::String, startstr::String, endstr::String)
|
||||
# check whether startstr is in the text or not
|
||||
isStartStr = split(text, startstr)
|
||||
if length(isStartStr) > 2
|
||||
return (success=false, error="There are more than one occurrences of the start string '$startstr' in the text. Text must has only one start string", errorcode=2, result=nothing)
|
||||
elseif length(isStartStr) == 1
|
||||
return (success=false, error="There are no start string '$startstr' in the text. Text must has only one start string", errorcode=1, result=nothing)
|
||||
end
|
||||
|
||||
# check whether endstr is in the text or not
|
||||
isEndStr = split(text, endstr)
|
||||
if length(isEndStr) > 2
|
||||
return (success=false, error="There are more than one occurrences of the end string '$endstr' in the text. Text must has only one end string", errorcode=3, result=nothing)
|
||||
elseif length(isStartStr) == 1
|
||||
return (success=false, error="There are no end string '$endstr' in the text. Text must has only one end string", errorcode=4, result=nothing)
|
||||
end
|
||||
|
||||
s = string(split(isStartStr[2], endstr)[1])
|
||||
|
||||
return (success=true, error=nothing, errorcode=0, text=s)
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
Determines if the given string follows camel case naming convention.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user