AnswerBun.com

Incorrect number or type of arguments when using @contains[ ]

Mathematica Asked by Mara Luisa Amada Tercero on December 12, 2020

I tried to make the old code you suggested me a little faster by doing this changes:

Needs["JLink`"]

Scanner[archivo_String, palabra_String] :=
 [email protected]
  Module[{entrada, linea, numlinea, contiene, ruta}, numlinea = 1; 
   linea = ""; contiene = False;
   InstallJava[];
   ruta = JavaNew["java.io.File", archivo];
   entrada = JavaNew["java.util.Scanner", ruta];
   Print["Archivo: " <> [email protected][]];
   Print["Texto a buscar:" <> palabra];
   While[[email protected][], linea = [email protected][]; 
    If[JavaNew["java.lang.String", linea]@contains[palabra], 
     Print["Linea:" <> numlinea <> ":" <> linea];
     contiene = True]; numlinea++]; 
   If[! contiene, Print[ palabra <> " no se ha encontrado"]]]

But I get this and don’t know why. It’s not working cause "issue" appears several times.

enter image description here

Hope you can help me

One Answer

The contains method requires a java.lang.String (or some other implementation of the CharSequence interface), not a Wolfram Language expression. Try using contains[[email protected]] instead of contains[palabra]. There are more messages after that is fixed, I haven't looked at those.

Correct answer by Jason B. on December 12, 2020

Add your own answers!

Related Questions

Fill in the hollow Spheres – generate solid spheres

1  Asked on December 26, 2020 by charis-sideris

   

How to extract data and attribute data from an XMLElement

2  Asked on December 25, 2020 by user74549

   

Set the same color scale across multiple ListContourPlots?

2  Asked on December 25, 2020 by doug-kimzey

     

Show Graphics on top of ParametricPlot3D

1  Asked on December 25, 2020 by sdnnds

   

DSolve[] and initial conditions

0  Asked on December 24, 2020 by daniel-huber

   

How to create some macros

2  Asked on December 24, 2020 by cyrille-piatecki

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP