0

I want to extract a specific part from a string in Spark

for e.g. my string is

val b= "URL ftp://216.24.126.75/serversoftware/ocs/OCS_Inventory_NGInstallation_and_Administration_Guide_1.7_EN.odt
MENTION cryptography    201564  http://en.wikipedia.org/wiki/Cryptography
MENTION digital signature   201870  http://en.wikipedia.org/wiki/Digital_signature
TOKEN   decide  153579
TOKEN   Analyze 160938
TOKEN   properly    140437
TOKEN   reselect    78017
TOKEN   writing 60758 "

and I want output like this:

(ftp://216.24.126.75/serversoftware/ocs/OCS_Inventory_NGInstallation_and_Administration_Guide_1.7_EN.odt,http://en.wikipedia.org/wiki/Cryptography)
(ftp://216.24.126.75/serversoftware/ocs/OCS_Inventory_NGInstallation_and_Administration_Guide_1.7_EN.odt,http://en.wikipedia.org/wiki/Digital_signature)
pault
  • 41,343
  • 15
  • 107
  • 149
  • You can probably this method on your string = yourstring.contains("put what you are searching for here"). And if you want to concat the strings together, you can just do string a + string b. – GamingFelix Oct 29 '19 at 10:49
  • Also, if you wanna pick out that certain string you're wanting to find I'd probably do b.subString(indexOf( theStringYouAreSearchingFor ), + Length of the content you are searching for ). If this seems confusing, look up String methods, indexOf and subString. Also I don't know Spark well, so maybe there's an easier way to do it in Spark, but this is using Scala methods that I am suggesting. – GamingFelix Oct 29 '19 at 10:51

0 Answers0