Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – Change whole string when substring contains certain chars

Posted on November 11, 2022 By

Solution 1 :

Use String#contains:

String bc = barcode.displayValue
if (bc.contains("CZV")) {
    bc = "LOKO";
}
barcodeValue.setText(bc);

Solution 2 :

String bc = barcode.displayValue
bc = bc.contains("CZV") ? "LOKO" : bc;
barcodeValue.setText(bc);

Solution 3 :

You can use the contains function:

String myString = barcode.displayvalue;
if(myString.contains("CZC")){
    myString = "replaced";
}

Problem :

If a string of a barcode scan (f.e.) contains “CZC” I want to be able to change the whole string into (f.e.) “LOKO”.


if (data != null) {
                    Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                    statusMessage.setText("Strichcode erfolgreich gelesen");
                    barcodeValue.setText(barcode.displayValue);
                    Log.d(TAG, "Strichcode Scannen: " + barcode.displayValue);

This part and more of the code that I have already written is supposed to change the whole string if “CZC” is contained.

Comments

Comment posted by Scalway

Question: You need to detect if string contains substring. If yes set barcode value to whatever you want. Just use

READ  [FIXED] android - How to get instance of the Application Class?
Powered by Inline Related Posts
Android Tags:android, java

Post navigation

Previous Post: [FIXED] android – how to change notification background color in nougat?
Next Post: [FIXED] android – How to make width ratio equal in XML GridView

Related Posts

[FIXED] android – How to populate statistics by Json data with dynamic keyword? Android
[FIXED] java – Firebase Database : How I can search anywhere without specifying the key Android
[FIXED] kotlin – Android service is killed 10 seconds after start Android
[FIXED] How to implement google map API key in Android sent from backend API response Android
[FIXED] java – How to check if a query process is finished in firebase Android
[FIXED] android – How to implement a RecyclerView when using Model View Presenter pattern? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme