Bits & Bytes

Posts Tagged ‘find’

How to Find Your IP Address

To start, there are internal and external IP addresses. Your internal IP address is the one that other computers can use on your local area network (LAN) to locate your machine. Your external IP address is the one that you use to contact external websites on the internet.

Internal IP Address Ranges

There three ranges for internal websites:

  • to – Class A
  • to – Class B
  • to – Class C

Internal IP addresses are always in one of these ranges. That is one way to tell if it is an internal or external IP address. Note that the first range fixes the first eight bits. The second fixes the first 12 bits. Finally, the third fixes the first 16 bits. That explains why the ranges are what they are.

To find your internal IP address, open a command prompt and type ipconfig, as shown below.

Notice that the internal IP address (IPv4), of this computer, is

External IP Address

Your external IP address can be determined by any website to which you connect.

This one will report it to you:

FIX: NU1101: Unable to find package Microsoft.EntityFrameworkCore.SqlServer

This is a general fix for any NuGet package that can not be found. Open the Options dialog by selecting Tool->NuGet Package Manager->Package Manager Settings. This is will open the dialog shown below. Select NuGet Package Manager->Package Sources as shown:

Click the Plus Button to select a new source. Fill in the name as Nuget and the Source: as and click Update and OK.

You might still need to set the package source. Right Click Dependencies->Packages in the Solution Explorer and select Manage NuGet Packages… to open the NuGet Package Manager Pane.

Now, just select NuGet as the Package source: as shown above and that should fix it.

PHP: How to Find a Substring in a String

How do you find a substring within a string? In PHP, the answer is not quite as straightforward as it should be. But, it’s still easy to do–you just need to be aware of a couple things.

Suppose we have the string “ABCDEFG”. There are two cases we want to look at: when we want to find “DEF” in the middle of the string, and when we want to find “ABC” at the beginning.

The function to find a substring is called strpos(). It can take up to three parameters:

strpos($haystack, $needle, $offset);

  1. $haystack: (required) the full string we want to search within
  2. $needle: (required) the substring we are searching for
  3. $offset: (optional) if we want the function to start looking for the substring at a position which is not at the beginning of the $haystack

When we call strpos() on the string, it will return the position of the substring as an integer (starting from 0), if it finds it. If it doesn’t find the substring, it will return false (which is 0 in PHP). So, when we search for “DEF”, the function will return 3 which is the position of the “D” (base 0). However, when we search for “ABC”, strpos() will return 0 because it found the substring at position 0.

So, we have to construct our code in this way to check the return value from the function:

$ret = strpos("ABCDEFG", "ABC");

if($ret === false) {
    echo("We did not find the substring.");
} else {
    echo("We found the substring!");

Here are some sample cases:

strpos(“ABCDEFG”, “ABC”); –> returns integer 0, substring found

strpos(“ABCDEFG”, “DEF”); –> returns integer 3, substring found

strpos(“ABCDEFG”, “XYZ”); –> returns a 0 = to PHP’s false keyword. substring not found

In the above code, the operator === checks whether two values are identical, which means whether the two values are of the same PHP type. The strpos() function will return a 0 that is equivalent to the false keyword in PHP if it does not find the substring. It will return an integer 0 if it finds the substring starting at position 0.  So, we use the operator which checks whether the two values are identical, and if a 0 was returned, whether the function meant that 0 to be false or to be the position of the substring it found.


© 2007–2024 LLC. All rights reserved.