This commit is contained in:
2026-07-12 10:48:01 +07:00
parent bd5022c8bc
commit c4eeb99aba
4 changed files with 34 additions and 11 deletions
+1 -7
View File
@@ -546,13 +546,7 @@ julia> clean_json_response(text)
"""
function clean_json_response(text::String)
removelist = ["{", "}", "```", "json", "\n"]
for i in removelist
while occursin(i, text)
text = replace(text, i => "")
end
end
text = '{' * text * '}'
return text
return '{' * removestring(text, removelist) * '}'
end
+30 -1
View File
@@ -5,7 +5,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep
dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString,
dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, issomething,
dictToString_numbering, extract_triple_backtick_text,
countGivenWords, remove_french_accents,
countGivenWords, remove_french_accents, removestring,
extractTextBetweenCharacter, extractTextBetweenString,
convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex
@@ -1139,9 +1139,38 @@ function nonRecentElementsIndex(vectorlength::Integer, n::Integer)
return 1:(vectorlength-n)
end
""" Remove specified substrings from text.
Removes all occurrences of each string in `removelist` from the input text
by repeatedly replacing them with empty strings until none remain.
# Arguments
- `text::String`
The input string to modify.
- `removelist::Vector{String}`
A vector of substrings to remove from the text.
# Return
- `String`: The text with all specified substrings removed.
# Examples
```jldoctest
julia> using GeneralUtils
julia> removestring("hello world", ["l", " "])
"heoword"
julia> removestring("foo bar baz", ["bar", " "])
"foobaz"
```
"""
function removestring(text::String, removelist::Vector{String})::String
for i in removelist
while occursin(i, text)
text = replace(text, i => "")
end
end
return string(text)
end