Forum Discussion
Error with Text.Trim
Can you eloborate a bit please.
The list of Punctuatuation is below. I added the .. ... !! !!! !!!! becasue of the source tweet text containing this to try and fix the issue.
The list
= {" ", "~", ",", ".", "..", ". .", "...", "....", ".....", "?", "!", "!!", "!!!", "!!!!", "!!!!!", ", ", (", "), "[", "]", "{", "}", "%", "^", "&", "*", "+", "=", ":", ";", "|", "<", ">", "/", """, """, "\", """", "#(tab)", "#(cr)", "#(lf)"}
In the Raviv book, the text is all nice and neet of course, real world data is unpredictable and not following an easy format.
I did not think this would be such an issue, to learn some M and to try out some textual clean up and analysis for an upcoming project.
HotChilli is correct. The Text.Trim function only takes a list of single characters.
For example, this does not work
But this does:
If you clean up your list to remove multi-character strings then it should work. For example, try this definition:
{" ", "~", ",", ".", "?", "!", "(", ")", "[", "]", "{", "}", "%", "^", "&", "*", "+", "=", ":", ";", "|", "<", ">", "/", """", "\", "#(tab)", "#(cr)", "#(lf)"}- DemoFour3 years agoContinued Contributor
HotChilli AlexisOlson
Thanks guys, so the previous error I was getting because the column had multiple strings. That makes sense.
Can you suggest a robust way to remove the multi stings, or is it a case of manually using replace text for all combinations - I feel that this is not very scaleable, so may brake the query.
Thanks for taking the time to respond.- ronrsnfld3 years agoSuper User
What are you asking?
Text.Trim(Text, Trim) is going to remove all the characters in the Trim list from the beginning or end of Text. If your string ends with "!!!" and you have "!" in Trim, it will remove all of the "!"'s. You only need a single character listed.
If your use case is different, please clarify. For example, if the characters in Trim are not at the beginning or end.
- DemoFour3 years agoContinued Contributor
ronrsnfld
thank you for your response.
I have !!! etc. at the end of sets of text, So you are saying that just having ! in the list will remove all of them.
There are all sorts of random punctuations as it is twitter data and people do strange things to put emphasis on the point.
Ok I will revise and see what happens