?
Solved

How to find string values based on a string with multiple possibilities

Posted on 2009-07-10
1
Medium Priority
?
236 Views
Last Modified: 2012-05-07
Hi!

What i want to do is the folowing.

I have a string called currentCodeLine this line is filled with a code line read from a source (a 4G language)

I also have a string called declaredVariables, containing: "iused inotused"

now i want to check if one or more of the words in the declaredVariables is in the currentCodeLine string.

I have tried to use the indexof, contains etc, but probably it can only search for a single word at a time.

Regards
Martin
0
Comment
Question by:MrHswede
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 375 total points
ID: 24825538
Try something like this, using Split to break your variables up then foreach syntax to search each once at a time.  Yes think your issue is that those variables probably don't appear together in sequence with a space so you won't get any matches unless you check independently.
string currentCodeLine = "iused x = some value that is inotused";
            string declaredVariables = "iused inotused";
            int count = 0;
 
            foreach (string s in declaredVariables.Split(" ".ToCharArray())) {
                if (currentCodeLine.Contains(s)) count++;
            }
 
            Console.WriteLine(String.Format("Found {0} instances!", count));

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question