Jul 15, 2019 Replies: 2 To remove lenefeeds and carriage return/line feeds from inside strings and replace them with a single space. Code: Copy Dim jo As JavaObject = Regex.matcher("[/\r?\n|\r/]", TextToClean) Return jo.RunMethod("replaceAll", Array(" ")) It might be straightforward if you're familiar with regular expressions, but it took me a while to find something that worked. Click to expand...
To remove lenefeeds and carriage return/line feeds from inside strings and replace them with a single space. Code: Copy Dim jo As JavaObject = Regex.matcher("[/\r?\n|\r/]", TextToClean) Return jo.RunMethod("replaceAll", Array(" ")) It might be straightforward if you're familiar with regular expressions, but it took me a while to find something that worked.
S sorex Expert Licensed User Longtime User Jul 16, 2019 #2 isn't this working aswell without the need for the extra javaobject library? Code: Copy return Regex.Replace("[/\r?\n|\r/]",TextToClean," "))
isn't this working aswell without the need for the extra javaobject library? Code: Copy return Regex.Replace("[/\r?\n|\r/]",TextToClean," "))
gravel Member Licensed User Longtime User Jul 16, 2019 #3 sorex said: isn't this working aswell without the need for the extra javaobject library? Code: Copy return Regex.Replace("[/\r?\n|\r/]",TextToClean," ")) Click to expand... Yes, I think you're right. This was probably lazyness on my part. After using the similar code to remove embeded multiple spaces in strings https://www.b4x.com/android/forum/threads/remove-multiple-spaces-inside-strings.107672/, I eventually ran into a string with multiple CrLF's and my approach to dealing with it must have been 'limited' by my previous thing with the multiple spaces
sorex said: isn't this working aswell without the need for the extra javaobject library? Code: Copy return Regex.Replace("[/\r?\n|\r/]",TextToClean," ")) Click to expand... Yes, I think you're right. This was probably lazyness on my part. After using the similar code to remove embeded multiple spaces in strings https://www.b4x.com/android/forum/threads/remove-multiple-spaces-inside-strings.107672/, I eventually ran into a string with multiple CrLF's and my approach to dealing with it must have been 'limited' by my previous thing with the multiple spaces